0% found this document useful (0 votes)
73 views4 pages

Inserting Multiple Rss Feeds Into MYSQL With Simplexml

The document discusses inserting multiple RSS feeds into a MySQL database using SimpleXML in PHP. The code provided loads multiple RSS feed URLs into an array, then loops through each feed URL to parse it with SimpleXML. For each item in the RSS feed, it inserts title, description, link and publish date into the database. The code was not working when trying to parse multiple feeds, so suggestions were provided to fix it by looping through each feed URL separately before parsing the items.

Uploaded by

Khoirul Anwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views4 pages

Inserting Multiple Rss Feeds Into MYSQL With Simplexml

The document discusses inserting multiple RSS feeds into a MySQL database using SimpleXML in PHP. The code provided loads multiple RSS feed URLs into an array, then loops through each feed URL to parse it with SimpleXML. For each item in the RSS feed, it inserts title, description, link and publish date into the database. The code was not working when trying to parse multiple feeds, so suggestions were provided to fix it by looping through each feed URL separately before parsing the items.

Uploaded by

Khoirul Anwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Inserting multiple rss feeds into MYSQL with sim... http://techqa.info/programming/question/1026898...

Home (http://techqa.info/) / Programming (http://techqa.info/programming)


/ Inserting multiple rss feeds into MYSQL with simplexml ...

Inserting multiple rss feeds into MYSQL with simplexml


asked by smd (https://stackoverflow.com/users/1349641) on Apr 22 2012 14:54

(https://www.facebook.com/share.php?u=http://techqa.info/programming/question/10268986
/inserting-multiple-rss-feeds-into-mysql-with-simplexml&title=Inserting multiple rss feeds into
MYSQL with simplexml - php - mysql - xml - rss - simplexml)
(https://reddit.com/submit?url=http://techqa.info/programming/question/10268986/inserting-
multiple-rss-feeds-into-mysql-with-simplexml&title=Inserting multiple rss feeds into MYSQL with
simplexml - php - mysql - xml - rss - simplexml)
(https://twitter.com/share?url=http://techqa.info/programming/question/10268986/inserting-
multiple-rss-feeds-into-mysql-with-simplexml&text=Inserting multiple rss feeds into MYSQL with
simplexml)
(https://plus.google.com/share?url=http://techqa.info/programming/question/10268986
/inserting-multiple-rss-feeds-into-mysql-with-simplexml)
(https://vk.com/share.php?url=http://techqa.info/programming/question/10268986/inserting-
multiple-rss-feeds-into-mysql-with-simplexml)
(https://service.weibo.com/share/share.php?url=http://techqa.info/programming/question
/10268986/inserting-multiple-rss-feeds-into-mysql-with-simplexml)
(https://www.linkedin.com/shareArticle?url=http://techqa.info/programming/question
/10268986/inserting-multiple-rss-feeds-into-mysql-with-simplexml)
(https://www.xing.com/app/user?op=share&url=http://techqa.info/programming/question
/10268986/inserting-multiple-rss-feeds-into-mysql-with-simplexml)

Below is my code to parse multiple rss feeds into a mysql db. I do something wrong in the
foreach part I think, since there is no output. The db however, gets filled. When using 1
feed, the script works fine. Anybody sees what I do wrong? Many thanks in advance :)

1 of 4 05/16/2017 10:25 AM
Inserting multiple rss feeds into MYSQL with sim... http://techqa.info/programming/question/1026898...

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


7');
$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->d
escription)))."',
'".mysql_real_escape_string($item->link)."',
'".mysql_real_escape_string($item->pubdate)."')");
}

View original question (https://stackoverflow.com/questions/10268986)

1 Answers

web-nomad (https://stackoverflow.com/users/561269) Apr 23 2012 06:53

Try this:

2 of 4 05/16/2017 10:25 AM
Inserting multiple rss feeds into MYSQL with sim... http://techqa.info/programming/question/1026898...

<?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($ite
m->description)))."',
'".mysql_real_escape_string($item->link)."',
'".mysql_real_escape_string($item->pubdate)."')");
}
}
?>

Hope it helps.

3 of 4 05/16/2017 10:25 AM
Inserting multiple rss feeds into MYSQL with sim... http://techqa.info/programming/question/1026898...

Need hosting? (https://www.bluehost.com/track


/gracias/techqa)
Privacy Policy (http://techqa.info/page/privacy) Terms and Conditions (http://techqa.info/page/terms)
About (http://techqa.info/page/about)

4 of 4 05/16/2017 10:25 AM

You might also like