I have here a simple regex to get the src
attribute of an image from an html code saved in my datebase.
$imagePattern = '/img src=(["\'])(.*?)\1/';
preg_match_all($imagePattern , $html, $matched);
var_dump($matched);die();
I get the src
only when the <img>
tag is formatted like <img src='test.png' id='test_image'>
but when the image tag is formatted like <img id='test_image' src='test.png'>
, I can't get the src
. Yes I know my regex is specific if img tag
and src attribute
is consecutive. How can I get the src of an image if the tag is img
and has src
attribute? Thank you!