Matching SRC attribute of IMG tag using preg_match

前端 未结 6 1665
走了就别回头了
走了就别回头了 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:52

    Your expression is incorrect. Try:

    preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $row->introtext, $matches);
    

    Note the removal of brackets around img and src and some other cleanups.

提交回复
热议问题