0

我需要从此 rss 提要中获取图片网址。我正在使用 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;

}
4

1 回答 1

0

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

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

所以这个例子是

preg_replace_callback("#<img[^>]+src=[\"|']([^\"]*)[\"|']#",function($matches){print_r($matches[1]);return $matches[0];},' '.$STR.' ');
于 2013-02-08T10:36:17.510 回答