开发者

Regular expression match all image URLs [duplicate]

开发者 https://www.devze.com 2023-01-19 02:08 出处:网络
This question already has an answer here: Closed 12 years ago. Possible Duplicate: How to get IMG tag code from HTML document?
This question already has an answer here: Closed 12 years ago.

Possible Duplicate:

How to get IMG tag code from HTML document?

I need help to make preg_match_all() for every image URL on random page.

As far I do this

preg_match_all('/img[\d\D]+?src\=(\'|\")([\d\D]+?)(\'|\")/i', $page, $matches); 

But won't work for every page. Must match all possible image closed in img src also ones that doesn't look lik开发者_开发问答e images. thank you


use the html DOM parser -> http://simplehtmldom.sourceforge.net/

all you need to do then is use this code:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images
foreach($html->find('img') as $element)
       echo $element->src . '<br>';
0

精彩评论

暂无评论...
验证码 换一张
取 消