无法使用RSS源中的存储模块


Not work with the enclosure in RSS Feed

我的外壳有问题,无法从包括外壳在内的各种网站读取图像

我使用的代码是:

<?php
  $doc = new DOMDocument();
  $doc->load('http://www.example.com/feed/rss1.rss');
  $arrFeeds = array();
  $cnt=0;
  foreach ($doc->getElementsByTagName('item') as $node) {
      if($cnt == 5 ) {
       break;
     } 
    $itemRSS = array ( 
      'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
      'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
      'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
      'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
      'enclosure' => $node->getElementsByTagName('enclosure')->item(0)->nodeValue
      );
      $cnt++;
?>
<h2><a href="<?php echo $itemRSS['link']; ?>"><?php echo $itemRSS['title']; ?></a></h2>
<p><?php echo $itemRSS['desc']; ?></p>
<img src="<?php echo $itemRSS['enclosure']; ?>">
<?php  } ?>

你能告诉我哪里错了吗?感谢:)

enclosure标记不包含url作为值,它位于"url"属性中。试试这样的东西:

 'enclosure' => $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url')