Alfred Francis Alfred Francis - 9 months ago 84
PHP Question

Extracting links using preg_match_all

I want extract the path of images from a html page using PHP-preg_match_all(), the pattern is as follows

<img width="148" height="110" src="https://link1">
<img width="104" height="129" src="https://link2">
<img width="150" height="129" src="https://linkn">


I want to all the image path in an array.

Answer Source

Try:

preg_match_all("/<img .*?(?=src)src=\"([^\"]+)\"/si", $html, $m); 
print_r($m);

OR

preg_match_all("/<img .* src=\"([^']*?)\">/", $html, $m);
echo "<pre>";
print_r($m[1]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download