从rss feed获取图片网址?

时间:2013-02-08 10:33:51

标签: php regex rss

我需要从这个RSS Feed中获取图片网址。 我正在使用dom文件获取数据

<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
  <channel>
    <title><![CDATA[Accessories]]></title>
    <link>http://abcde.com/accessories</link>
    <description><![CDATA[Accessories]]></description>
    <pubDate>Fri, 08 Feb 2013 10:16:45 +0000</pubDate>
    <generator>Zend_Feed</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <item>
      <title><![CDATA[Jabra HALO 2 JBRA2113 Wireless Headset]]></title>
      <link>http://abcde.com/accessories/jabra-halo-2-jbra2113-wireless-headset</link>
      <description><![CDATA[<table><tr><td><a href="http://abcde.com/accessories/jabra-halo-2-jbra2113-wireless-headset"><img src="http://abcde.com/media/catalog/product/cache/1/thumbnail/75x75/9df78eab33525d08d6e5fb8d27136e95/h/a/halo2_frontview_1440x810.jpg" border="0" align="left" height="75" width="75"></a></td><td  style="text-decoration:none;">






    <div class="price-box">
                                                            <span class="regular-price" id="product-price-1041"><span class="price">Rs. 6,499.00</span></span>

        </div>

</td></tr></table>]]></description>
      <pubDate>Fri, 08 Feb 2013 10:16:45 +0000</pubDate>
    </item>

  </channel>
</rss>

预期产出:

http://abcde.com/media/catalog/product/cache/1/thumbnail/75x75/9df78eab33525d08d6e5fb8d27136e95/h/a/halo2_frontview_1440x810.jpg

现在我得到这样的细节......

$doc = new DOMDocument();
$doc->load('http://feeds.gawker.com/lifehacker/full');
$arrFeeds = array();
foreach ($doc->getElementsByTagName('item') as $node) {

$a = $node->getElementsByTagName('title')->item(0)->nodeValue;
$a = $node->getElementsByTagName('image')->item(0)->nodeValue;

}

1 个答案:

答案 0 :(得分:0)

也许你只想获得img src-s:

"#<img[^>]+src=[\"|']([^\"]*)[\"|']#"

所以示例是

preg_replace_callback("#<img[^>]+src=[\"|']([^\"]*)[\"|']#",function($matches){print_r($matches[1]);return $matches[0];},' '.$STR.' ');