2012-04-22 2 views
0

아래는 MySQL 데이터베이스에 여러 RSS 피드를 구문 분석하는 코드입니다. 출력이 없으므로 foreach 부분에서 뭔가 잘못 생각합니다. 그러나 db는 채워집니다. 1 개의 피드를 사용하면 스크립트가 정상적으로 작동합니다. 내가 뭘 잘못한 사람이 보이니? 사전에 많은 감사합니다 :)Simplexml로 MYSQL에 여러 RSS 피드 삽입

$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

위대한, 그랬어! 나는 영예를 잊기 위해 어리 석었다. 이 스크립트에 관한 또 하나의 질문 : 나는 또한 pubdate notation/date 형식과 strtotime에 문제가 있었음에 틀림 없다 : 스크립트가 시간을 올바르게 반영하지만, – smd