How to find a URL from a content by PHP?

后端 未结 2 851
孤独总比滥情好
孤独总比滥情好 2021-01-23 09:28

need a simply preg_match, which will find \"c.aspx\" (without quotes) in the content if it finds, it will return the whole url. As a example

$content = \'
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-23 10:24

    If you want to find any quoted string with c.aspx in it:

    /"[^"]*c\.aspx[^"]*"|'[^']*c\.aspx[^']*'/
    

    But really, for parsing most HTML you'd be better off with some sort of DOM parser so that you can be sure what you're matching is really an href.

提交回复
热议问题