What are the differences between using "<.*img.*>" and ".*img.*" in preg_match_all in PHP?

Using "<.*img.*>" in preg_match_all will match any string that contains the word "img" within HTML tags, such as <img src="image.jpg">. On the other hand, using ".*img.*" will match any string that contains the word "img" without considering HTML tags. Therefore, if you specifically want to match "img" within HTML tags, you should use "<.*img.*>".

// Using &quot;&lt;.*img.*&gt;&quot; to match &quot;img&quot; within HTML tags
$string = &#039;&lt;img src=&quot;image.jpg&quot;&gt;&#039;;
preg_match_all(&#039;/&lt;.*img.*&gt;/&#039;, $string, $matches);
print_r($matches[0]);