Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP显示RSS_Php_Xml_Rss - Fatal编程技术网

用PHP显示RSS

用PHP显示RSS,php,xml,rss,Php,Xml,Rss,我正在尝试用php创建一个页面,用于显示RSS中的一些新闻。我从互联网上得到了一个例子: 这与他们的url配合得很好。但当我尝试我的,它只是显示1970年的日期。这是我的网址: 我试图知道为什么我的失败,但他们提供的xml几乎和我的一样,所以我不知道它是怎么失败的 你能给我一些线索或想法吗?我无法更改我的xml,因此如果必须进行任何更改,它应该是php代码。尝试使用DateTime::createFromFormat进行日期转换。我认为问题在于我在foreach结构中读取内容的方式。因为如果

我正在尝试用php创建一个页面,用于显示RSS中的一些新闻。我从互联网上得到了一个例子:


这与他们的url配合得很好。但当我尝试我的,它只是显示1970年的日期。这是我的网址:

我试图知道为什么我的失败,但他们提供的xml几乎和我的一样,所以我不知道它是怎么失败的


你能给我一些线索或想法吗?我无法更改我的xml,因此如果必须进行任何更改,它应该是php代码。

尝试使用
DateTime::createFromFormat
进行日期转换。我认为问题在于我在foreach结构中读取内容的方式。因为如果我写回音“a”;在里面,它永远不会被写出来。
<?php
$rss = new DOMDocument();
$rss->load('http://portal.ayto-santander.es/portal/page/portal/inet_santander/ayuntamiento/concejalias/juventud/actividades/rss_actividades');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = 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,
        );
    array_push($feed, $item);
}
$limit = 5;
for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date = date('l F d, Y', strtotime($feed[$x]['date']));
    echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
    echo '<small><em>Posted on '.$date.'</em></small></p>';
    echo '<p>'.$description.'</p>';
}
?>