Results 1 to 9 of 9
Thread: A Simple RSS Feed Phraser in PHP
-
07-17-2005, 07:32 AM #1Web Hosting Guru
- Join Date
- Oct 2002
- Location
- York, United Kingdom
- Posts
- 279
A Simple RSS Feed Phraser in PHP
Heres a simple RSS Feed Phraser function. Its simple and effective function. All you need to do is add it to the page you wish to display the feed.
If you want to show / display the feed all you need to do is call up the function using:
PHP Code:showFeed($url,$count);
$url = the url of the rss feed (e.g. http://slashdot.org/slashdot.rdf)
$count = the number of titles and descriptions to display (e.g. 5)
Using this function you can display more than one rss feed in one page / file, without constantly rewriting out all the code to display the feed. The function:
PHP Code:function showFeed($url,$count)
{
//* get the xml file
$xml = simplexml_load_file($url);
//* phrase all the data from the xml so we can display it
for ($x = 0; $x < $count; $x++) {
//* this bits for if its an rss 1 feed
if (isset($xml->item)) {
$item = $xml->item[$x];
}
//* this bits for 0.91 rss feeds
elseif (isset($xml->channel->item)) {
$item = $xml->channel->item[$x];
}
//* show the headline and the description
echo "<a href=\"$item->link\">$item->title</a><br>$item->description<br><br>";
}
//* reset variables
unset($xml);
unset($item);
//* close the function loop
}
Enjoy!
Let me know if you need any help!Last edited by adaml; 07-17-2005 at 07:36 AM.
adamlivesley
http://84degrees.com
-
07-22-2005, 05:02 AM #2Web Hosting Guru
- Join Date
- Oct 2002
- Location
- York, United Kingdom
- Posts
- 279
Did anyone find this useful ?
adamlivesley
http://84degrees.com
-
08-28-2005, 01:20 AM #3Web Hosting Master
- Join Date
- May 2005
- Location
- Mumbai, India
- Posts
- 555
Works in PHP 5 only - for versions < 5, xml_parse function has to be used.
-
08-28-2005, 10:08 PM #4Newbie
- Join Date
- Jul 2004
- Posts
- 29
is this true? it won't work with PHP4x? How about an example with PHP4x?
Thanks
Charles<<Please see rules for signature setup>>
-
08-28-2005, 10:22 PM #5Web Hosting Guru
- Join Date
- Oct 2002
- Location
- York, United Kingdom
- Posts
- 279
yes its true, $xml came proberly builtin in version 5. you can use fopen to read an xml feed though
but i still think php 5 has been through enough testing so its all stable and working.adamlivesley
http://84degrees.com
-
08-28-2005, 10:27 PM #6Newbie
- Join Date
- Jul 2004
- Posts
- 29
but my host only has php4 installed....no 5.
Charles<<Please see rules for signature setup>>
-
09-02-2005, 02:10 AM #7Junior Guru Wannabe
- Join Date
- Nov 2004
- Posts
- 30
Thanks a lot.
-
09-02-2005, 02:15 AM #8Web Hosting Master
- Join Date
- May 2005
- Location
- Mumbai, India
- Posts
- 555
Originally posted by bigmac99
but my host only has php4 installed....no 5.
Charles
-
09-02-2005, 08:26 PM #9Web Hosting Guru
- Join Date
- Oct 2002
- Location
- York, United Kingdom
- Posts
- 279
PHP 5 has no problems handling PHP 4 Applications or sites. Well iv had no troubles yet with my hosting clients, and we upgraded to PHP 5 a while back now.
Just waiting for cPanel to fully support MySQL 5 As that can handle procedures!adamlivesley
http://84degrees.com