how can i get first img from html code by php
php
Solution
Use `preg_match` function
preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $text, $img);
echo $img[1]; // http://localhost/1.png
Problem
i want get first img from html code by php i have this code ``` $text = ' <b>hello</b> this is the first img <img src="http://localhost/1.png" title="first img" /> other img <img src="http://localhost/2.png" title="other" /> '; ``` I want the first source image in a new variable ``` http://localhost/1.png ``` thanks