2

你好!我有一个内容

<p>
    <a href="http://haha.yellowandred.in/wp-content/uploads/2012/07/535540_273587499393207_2112055176_n.jpg">
        <img class="aligncenter size-medium wp-image-9" title="Reasons heals nothing" src="http://haha.yellowandred.in/wp-content/uploads/2012/07/535540_273587499393207_2112055176_n-212x300.jpg" alt="" width="212" height="300" />
    </a>
</p> 
<p>
    The post <a href="http://haha.yellowandred.in/reasons-heals-nothing/">Reasons heals nothing</a> appeared first on <a href="http://haha.yellowandred.in">haha</a>.
</p>

从这个内容中,我必须只获取图像标签及其属性。

我怎么能这样?

我用过preg_match()但我不能做我需要的所以有人可以帮助我吗?

4

2 回答 2

1

这应该让你走上正确的道路。除非绝对必要,否则不要使用正则表达式。

SimpleHtml DOM 解析器

于 2012-07-31T05:11:53.950 回答
0

如果您愿意,使用 jQuery 是另一种方式

$(document).ready(){

var src = $('p a').find('img').attr('src');
var title = $('p a').find('img').attr('title');
var classname = $('p a').find('img').attr('class');

alert('Title:'+title+'\n'+'Source:'+src+'\n'+'Class:'+classname);

});
于 2012-07-31T05:27:46.243 回答