Jump to content

RSS into a MYSQL database


phpnewby1918

Recommended Posts

Hi,

 

I'm trying to broaden my scope with RSS feeds. Basically I want to be able to pull data from an RSS feed from either somewhere big like BBC or even a friends site but then be able to input this data into a mysql database. I do know there is a program RSS2MYSQL (I think) But i'd like to learn the script behind it. If i take the this script from w3schools shown below:

 

XML FILE:

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<note>

<to>Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

 

And then use this code to echo the data out (Shown below):

 

<?php

$xml = simplexml_load_file("test.xml");

 

echo $xml->getName() . "<br />";

 

foreach($xml->children() as $child)

  {

  echo $child->getName() . ": " . $child . "<br />";

  }

?>

 

Obviosuly this works great but i'm then unsure how i'd be able to add this data into my database. Could anybody help me out with how i'd go about doing this please?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/199573-rss-into-a-mysql-database/
Share on other sites

hello

basically what "simplexml_load_file" converts any well-formed XML file to an object. Onc it is converted you can use all the methods in the SimpleXMLElement class. getName() and children() are functions within this class.

 

To understand more about this topics see these links:

simplexml_load_file

The SimpleXMLElement class

 

It is always a good idea to check the php manual beforhand.

 

hope this helps

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.