2016-10-08 68 views
1

我有一块PHP与我的RSS源交谈并导入它。问题是,它决定返回一个500内部服务器错误,我似乎无法弄清楚为什么。我已经使用此代码与以前的饲料,它完美的工作。但随着这种新的饲料它打破。有任何想法吗?RSS源导入返回500内部服务器错误

在此先感谢!

<?php 
    $doc = new DOMDocument(); 
    $doc->load('http://guiltyfeminist.com/rss'); 
    $cnt=0; 

    foreach ($doc->getElementsByTagName('item') as $node) { 
    $itemRSS = array ( 
    'maintitle' => $node->getElementsByTagName('title')->item(0)->nodeValue, 
    'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 
    'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, 
    'enclosure' => $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url'), 
    ); 
    ?> 
    <div class="showcontent"> 
     <div class="contentleft"> 
     <img src="<?php echo $node->getElementsByTagNameNS('http://www.itunes.com/dtds/podcast-1.0.dtd', 'image')->item(0)->getAttribute('href'); ?>"> 
     </div> 
     <div class="contentright"> 
      <h2><a href="<?php echo $itemRSS['link']; ?>"><?php echo $itemRSS['maintitle']; ?></a></h2> 
      <p><strong>Duration</strong> <?php echo $node->getElementsByTagNameNS('http://www.itunes.com/dtds/podcast-1.0.dtd', 'duration')->item(0)->nodeValue; ?></p> 
      <p><strong>Published</strong> <?php echo $itemRSS['date']; ?></p> 
      <audio controls> 
       <source src="<?php echo $itemRSS['enclosure']; ?>" type="audio/mpeg"> 
      Your browser does not support the audio element. 
      </audio> 
     </div> 
    </div> 

    <?php $cnt ++; } ?> 

回答

1

你的代码工作正常。你可以尝试在另一台电脑上使用相同的代码

+0

我试过了,但是我得到这个错误“致命错误:调用成员函数getAttribute()null ...” 它指向这一行:''enclosure '=> $ node-> getElementsByTagName('enclosure') - > item(0) - > getAttribute('url'),' 任何想法,我可以解决这个问题。我知道它说空引用,但我如何修复上面的代码来防止这种情况。 –

相关问题