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

时间:2014-09-22 07:40:55

标签: php html

<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.I能够逐个获取img标签.HTML中有多个img标签。如何使用PHP获取这些img标签?

2 个答案:

答案 0 :(得分:0)

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

The DOMXPath class 该页面底部有一个很好的样本。

答案 1 :(得分:0)

你可以试试这个

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

print_r($allTags);