08-06-2010, 09:23 PM
For a long time, I struggled to get RSS to play nicely with PHP. After much research and revising PHP, I finally got some script that works.
The first thing to realise is that RSS is just XML, if you'd like to learn more about XML head over to http://www.w3schools.com
I will walk you through how my code works.
$xml should equal your RSS feed. Mine points to my ThoughtSpeech blog.
The rest basically loads the feed into a variable that we can now edit. So we carry on.
Lets start with
This assigns $post with an array with all of the "items" or posts from your Blog.
Now lets examine part of the foreach loop, from which you can work out the rest of it. The rest of the foreach that I show you will examine the Title tag, but it can be applied to the others with a few small changes.
This examines the $post/$item variable for all the elements with the name "title", it then assigns it too $Title.
This part of code is completely optional, it creates an array `creatively` named $Title_Array, with all of the titles in it.
Note: When getting tags, please note that they are case-sensitive.
Until Next Time
-Drumm
The first thing to realise is that RSS is just XML, if you'd like to learn more about XML head over to http://www.w3schools.com
I will walk you through how my code works.
PHP Code:
<?php
//BLOG
$xml=("http://thoughtspeech.wordpress.com/feed/");
$xmlDoc = new DOMDocument();
$xmlDoc->preserveWhiteSpace = false; //ignore useless childNodes which are just blank space
$xmlDoc->load($xml);
?>
The rest basically loads the feed into a variable that we can now edit. So we carry on.
PHP Code:
<?php
//BLOG
$xml=("http://thoughtspeech.wordpress.com/feed/");
$xmlDoc = new DOMDocument();
$xmlDoc->preserveWhiteSpace = false; //ignore useless childNodes which are just blank space
$xmlDoc->load($xml);
$value = 0;
$post = $xmlDoc->getElementsByTagName( "item" );
foreach( $post as $item )
{
$Titles = $item->getElementsByTagName( "title" );
$Title = $Titles->item(0)->nodeValue;
$Descs = $item->getElementsByTagName( "description" );
$Desc = $Descs->item(0)->nodeValue;
$Links = $item->getElementsByTagName( "link" );
$Link = $Links->item(0)->nodeValue;
$Title_Array[$value] = $Title;
$Description_Array[$value] = $Desc;
$Link_Array[$value] = $Link;
$value++;
}
Lets start with
PHP Code:
$post = $xmlDoc->getElementsByTagName( "item" );
Now lets examine part of the foreach loop, from which you can work out the rest of it. The rest of the foreach that I show you will examine the Title tag, but it can be applied to the others with a few small changes.
PHP Code:
$Titles = $item->getElementsByTagName( "title" );
$Title = $Titles->item(0)->nodeValue;
PHP Code:
$Title_Array[$value] = $Title;
$value++;
Note: When getting tags, please note that they are case-sensitive.
Until Next Time
-Drumm
;7$=v?%v%#5>v7v8994
The decrypt code is V, I could not make it any simpler!