Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,362 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,267 people online right now. Registration is fast and FREE... Join Now!




How to integrate RSS feed in my site?

 
Reply to this topicStart new topic

How to integrate RSS feed in my site?

cygnusX
post 29 Sep, 2008 - 09:15 AM
Post #1


D.I.C Head

**
Joined: 19 May, 2007
Posts: 159


My Contributions


As far as i know i can do it by placing the feeds into .xml file or insert the feeds into a database and retrieve them with PHP.Ok,i know how to do it by placing the feed contents in .xml file but i want to have the feeds in the database,so how to do it?I mean i just have to echo the contents or what?

User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 29 Sep, 2008 - 06:38 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,027



Thanked 173 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Well you can have PHP go to a remote server, open up a stream and read the XML content and manipulate it as you see fit. If you want to then insert the XML content straight into a database, you can do that too. Just create a TEXT or NTEXT field type in your database and put it in there with a SQL insert. Don't make it more complicated than it has to be.

Look into SimpleXML which is enabled by default in PHP 5. With the simplexml_load_file() function you can pull in XML files from remote sites and parse them with the simplexml functions. Or you can use libxml which is also installed as part of the PHP core. These libraries will let you grab xml content, parse it into a string which you can then insert into a TEXT or NTEXT field that is big enough to store the content.

Then all your SQL has to do is read it from the database. Not that tricky really. Look into both those libraries and I am sure you will see how you can pull in the resource, parse it quickly and create a string that you can insert into your database for future use.

You could also suck the xml across using the function file_get_contents() and store it in raw form directly into the database. Mind you this way may not get all the XML tags so some content may be lost along the way, but depending on the XML it may be a solution.

Personally I would pull across the xml doc with simplexml_load_file and here is an example of using a DIC feed, sucking it across with simplexml_load_file and then accessing the first new topic...

php

<?php
// Load the feed for the Caffiene Lounge's newest topics from DIC site
$filecontent = simplexml_load_file("http://www.dreamincode.net/rss/forums.php?forum=1");
if ($filecontent != null) {
// Get the title of the first new topic post
echo "Caffiene Lounge first title: " . $filecontent->channel->item[0]->title;
}
else { echo "Couldn't fetch the content"; }
?>


Enjoy!

"At DIC we be xml sucking code ninjas... that and we just plain suck!" decap.gif

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 04:59AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month