2012-04-22 15 views
0

以下は、複数のrssフィードをmysqlデータベースに解析するコードです。 出力がないので、私はforeachの部分で何か間違っています。 しかし、dbは塗りつぶされます。フィードを1つ使用すると、スクリプトはうまく動作します。 誰かが私が間違っていることを見ていますか?事前に多くの感謝:)複数のRSSフィードをsimplexmlでMYSQLに挿入する

$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)."')");  
} 

答えて

0

これを試してみてください:

<?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)."')");  
    } 
} 
?> 

はそれがお役に立てば幸いです。

+0

ああ!どうもありがとう。 – smd

+0

偉大な、それをやった!私は賞賛を忘れるために馬鹿だった。このスクリプトに関するもう1つの質問:私は、公文表記/日付形式とstrtotimeに間違ったことをしているに違いありません。スクリプトは時刻を正確にエコーしますが、 – smd

関連する問題