2013-02-08 176 views
0

我需要從這個RSS提要獲取圖片網址。 我使用DOM文檔獲取獲取數據從rss feed獲取圖片網址?

<?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; 

} 

回答

0

也許你想只獲得img src -s:

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

所以這個例子就是

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