Php 使用simplexml将多个rss源插入MYSQL

Php 使用simplexml将多个rss源插入MYSQL,php,mysql,xml,rss,simplexml,Php,Mysql,Xml,Rss,Simplexml,下面是我将多个rss提要解析为mysql数据库的代码。 因为没有输出,我认为每个部分都做错了。 然而,数据库被填满了。使用1个提要时,脚本工作正常。 有人看到我做错了什么吗?非常感谢: $feeds = ('https://www.ictu.nl/rss.xml', 'http://www.vng.nl/smartsite.dws?id=97817'); $xml = simplexml_load_file($feeds); foreach($xml->channel->item

下面是我将多个rss提要解析为mysql数据库的代码。 因为没有输出,我认为每个部分都做错了。 然而,数据库被填满了。使用1个提要时,脚本工作正常。 有人看到我做错了什么吗?非常感谢:

$feeds = ('https://www.ictu.nl/rss.xml', 'http://www.vng.nl/smartsite.dws?id=97817');
$xml = simplexml_load_file($feeds);

foreach($xml->channel->item as $item)
{
$date_format = "j-n-Y"; // 7-7-2008
echo date($date_format,strtotime($item->pubDate));  
         echo '<a href="'.$item->link.'" target="_blank">'.$item->title.'</a>';
         echo '<div>' . $item->description . '</div>';

mysql_query("INSERT INTO rss_feeds (id, title, description, link, pubdate) 
VALUES (
    '', 
    '".mysql_real_escape_string($item->title)."', 
    '".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
    '".mysql_real_escape_string($item->link)."', 
    '".mysql_real_escape_string($item->pubdate)."')");       
}
试试这个:

<?php
$feeds = array('https://www.ictu.nl/rss.xml', 'http://www.vng.nl/smartsite.dws?id=97817');
foreach( $feeds as $feed ) {
    $xml = simplexml_load_file($feed);

    foreach($xml->channel->item as $item)
    {
    $date_format = "j-n-Y"; // 7-7-2008
    echo date($date_format,strtotime($item->pubDate));  
             echo '<a href="'.$item->link.'" target="_blank">'.$item->title.'</a>';
             echo '<div>' . $item->description . '</div>';

    mysql_query("INSERT INTO rss_feeds (id, title, description, link, pubdate) 
    VALUES (
        '', 
        '".mysql_real_escape_string($item->title)."', 
        '".mysql_real_escape_string($item->description=htmlspecialchars(trim($item->description)))."', 
        '".mysql_real_escape_string($item->link)."', 
        '".mysql_real_escape_string($item->pubdate)."')");       
    }
}
?>

希望有帮助。

太好了,成功了!我愚蠢地忘记了这些荣誉。关于这个脚本,还有一个问题:我肯定对pubdate符号/日期格式和strotime做了一些错误:尽管脚本正确地回显了时间,