5 Replies - 22531 Views - Last Post: 13 December 2011 - 06:17 PM Rate Topic: -----

#1 Will_00  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 64
  • Joined: 20-July 08

Automatically Save RSS Feed in Database

Posted 21 September 2008 - 09:07 PM

I was attempting to retrieve RSS feeds and save their information in a MySQL database, but am not sure how do that. Also, could it be possible to automatically retrieve the articles in the RSS feed and save them in the database?
Is This A Good Question/Topic? 0
  • +

Replies To: Automatically Save RSS Feed in Database

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,126
  • Joined: 18-April 07

Re: Automatically Save RSS Feed in Database

Posted 21 September 2008 - 09:27 PM

The first thing you should look at is the fopen function which you can specify a URL as the RSS feed location and it will read that RSS as a stream. Once you do that, read it into a string and save that string into MySQL. Or you can parse it using XML Parser functions or DOM Parsing functions to fetch out the content and save those to a database individually.

Then lastly is one of many tutorials to show you how parsing of RSS feeds can be done in PHP...

PHPBuilder.com - Reading RSS feeds in PHP: Part 1

Enjoy! ;)

This post has been edited by Martyr2: 21 September 2008 - 09:27 PM

Was This Post Helpful? 0
  • +
  • -

#3 akozlik  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 797
  • Joined: 25-February 08

Re: Automatically Save RSS Feed in Database

Posted 22 September 2008 - 01:35 PM

You might want to take a look at this snippet I wrote.

Just study the code and adapt it for your needs. At the very least it will show you how to parse an XML file.
Was This Post Helpful? 0
  • +
  • -

#4 x-mad  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-August 11

Re: Automatically Save RSS Feed in Database

Posted 22 August 2011 - 08:10 AM

Hi , this code snippet I made to grab feeds into my web x-mad.com
it is 2 functions..

basically if,
you have a database with at least the following fields : importedtitle,importedcontent,importedurl,importedcategory
if you run the following command you will have those fields populated.

getintodatabase1('Your RSS URL','Your Category','the xml node that contains the items','the xml node that contains the title','the xml node that contains the content','the xml node that contains the url','the xml node that contains the date');

and a real example :

getintodatabase1('http://feeds.feedburner.com/blogspot/bpoYR','Greek Cartoons','entry','title','content','id','published');
If you run again and again this command, you will not have any duplicates provided that on your database the importedtitle field is set as non duplicate.


Here is your functions :
function getintodatabase1($xmad_url,$cat,$itemnode,$titlenode,$contentnode,$urlnode,$datenode) 
{
$xmad_tags = array($titlenode,$contentnode,$urlnode,$datenode);
$xmad_item_tag = $itemnode;      
$xmadfeed = getintodatabase2($xmad_item_tag,$xmad_tags,$xmad_url,$cat,$titlenode,$contentnode,$urlnode,$datenode);
}
function getintodatabase2($tag, $array, $url, $cat,$titlenode,$contentnode,$urlnode,$datenode) 
{
$doc = new DOMdocument(); $doc->load($url); $xmad_array = array(); $items = array();
foreach($doc->getElementsByTagName($tag) AS $node) 
{ foreach($array AS $key => $value) 
{
$items[$value] = $node->getElementsByTagName($value)->item(0)->nodeValue;
$importeddate = $items[$datenode];$importedtitle = $items[$titlenode];$importedcontent = $items[$contentnode];$importedurl = $items[$urlnode];		
}
array_push($xmad_array, $items);
mysql_connect("dbhost", "db_username", "db_password") or die(mysql_error()); mysql_select_db("db_name") or die(mysql_error());
mysql_set_charset('utf8');
 $query = sprintf("INSERT INTO rssimports (importedtitle,importedcontent,importedurl,importedcategory) values ('%s','%s','%s','%s')",
	mysql_real_escape_string($importedtitle),
	mysql_real_escape_string($importedcontent),
	mysql_real_escape_string($importedurl),
	mysql_real_escape_string($cat));
	$result = mysql_query($query);
	}
mysql_close();
}



I hope I helped you and all others visiting this thread as it is top on google and I visited it before finding my solution!


If you replicated it, please put "thx x-mad" on the bottom :)

View PostWill_00, on 21 September 2008 - 09:07 PM, said:

I was attempting to retrieve RSS feeds and save their information in a MySQL database, but am not sure how do that. Also, could it be possible to automatically retrieve the articles in the RSS feed and save them in the database?

This post has been edited by x-mad: 22 August 2011 - 08:12 AM

Was This Post Helpful? 0
  • +
  • -

#5 dynosure  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-December 11

Re: Automatically Save RSS Feed in Database

Posted 08 December 2011 - 10:36 AM

I was also looking for a program like this.

To be honest, the most relevant one is the SimplePie class. But the cache function there also is not suitable for me.

So I wrote one my self saving information like title, feed id, full content, etc to MySQL database. And it worked smoothly. Check here for details.
Was This Post Helpful? 0
  • +
  • -

#6 dynosure  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-December 11

Re: Automatically Save RSS Feed in Database

Posted 13 December 2011 - 06:17 PM

View Postdynosure, on 08 December 2011 - 10:36 AM, said:

I was also looking for a program like this.

To be honest, the most relevant one is the SimplePie class. But the cache function there also is not suitable for me.

So I wrote one my self saving information like title, feed id, full content, etc to MySQL database. And it worked smoothly. Check here for details.


Here is the new link! http://blog.smerpup....implepie-class/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1