Matching SRC attribute of IMG tag using preg_match

前端 未结 6 1654
走了就别回头了
走了就别回头了 2020-12-03 08:06

I\'m attempting to run preg_match to extract the SRC attribute from the first IMG tag in an article (in this case, stored in $row->introtext).

preg_match(\'/         


        
6条回答
  •  借酒劲吻你
    2020-12-03 08:39

    The regex I used was much simpler. My code assumes that the string being passed to it contains exactly one img tag with no other markup:

    $pattern = '/src="([^"]*)"/';
    

    See my answer here for more info: How to extract img src, title and alt from html using php?

提交回复
热议问题