如何使用 php 从 html 中获取多个 img 标签


How to fetch multiple img tags from html using php?

<strong><a href="http://www.flickr.com/photos/therevsteve/5152424274/sizes/l/">
<img src="http://www.brightknowledge.org/knowledge-bank/teaching/teaching-in-private-  schools/@@images/77cbbd71-bbf5-4fb6-a017-cc61016b6f60.jpeg" alt="Teaching in private schools" class="image-right" title="Photo by Steve Day" /></a>
There are big differences between teaching in independent and state schools. Find out about the most important ones here.</strong><img src="http://www.brightknowledge.org/++resource++brightside.theme.images/badge.png" />

这是我的 HTML。我可以一一获取 img 标签。HTML 中有多个 img 标记。如何使用 PHP 获取这些 img 标签?

您可以使用 XPath 查询所有 img 节点。

DOMXPath 类该页面底部有一个很好的示例。

你可以试试这个

preg_match_all('/<img[^>]+>/i',$html, $allTags); 
print_r($allTags);