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 を使用するのも、やる気がある場合のもう 1 つの方法です。

$(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 に答える