1

可能重复:
如何从 HTML 文档中获取 IMG 标记代码?

我需要帮助为随机页面上的每个图像 URL 制作preg_match_all()
据我所知

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

但不适用于每一页。必须匹配在img src中关闭的所有可能的图像,以及那些看起来不像图像的图像。谢谢你

4

1 回答 1

1

使用 html DOM 解析器 -> http://simplehtmldom.sourceforge.net/

您需要做的就是使用以下代码:

// 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>';
于 2010-10-06T09:16:54.213 回答