hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Programming Tutorials : A Simple RSS Feed Phraser in PHP
Reply

Programming Tutorials How-Tos related to programming, databases, and the like.
Forum Jump

A Simple RSS Feed Phraser in PHP

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 07-17-2005, 07:32 AM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
Post

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); 
The $variables can be used to define a few options:

$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.
Reply With Quote


Sponsored Links
  #2  
Old 07-22-2005, 05:02 AM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
Did anyone find this useful ?

Reply With Quote
  #3  
Old 08-28-2005, 01:20 AM
anjanesh anjanesh is offline
Web Hosting Evangelist
 
Join Date: May 2005
Location: Mumbai, India
Posts: 549
Works in PHP 5 only - for versions < 5, xml_parse function has to be used.

Reply With Quote
Sponsored Links
  #4  
Old 08-28-2005, 10:08 PM
bigmac99 bigmac99 is offline
Newbie
 
Join Date: Jul 2004
Posts: 27
is this true? it won't work with PHP4x? How about an example with PHP4x?

Thanks
Charles

Reply With Quote
  #5  
Old 08-28-2005, 10:22 PM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
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.

Reply With Quote
  #6  
Old 08-28-2005, 10:27 PM
bigmac99 bigmac99 is offline
Newbie
 
Join Date: Jul 2004
Posts: 27
but my host only has php4 installed....no 5.

Charles

Reply With Quote
  #7  
Old 09-02-2005, 02:10 AM
Purple Butterfly Purple Butterfly is offline
Newbie
 
Join Date: Nov 2004
Posts: 29
Thanks a lot.

Reply With Quote
  #8  
Old 09-02-2005, 02:15 AM
anjanesh anjanesh is offline
Web Hosting Evangelist
 
Join Date: May 2005
Location: Mumbai, India
Posts: 549
Quote:
Originally posted by bigmac99
but my host only has php4 installed....no 5.

Charles
I've stopped asking hosts if they'll install PHP5. If a host still uses PHP4 now then its not worth hosting a new website there. The only reason hosting Cos still use PHP4 is because of compatibility for old PHP4 sites.

Reply With Quote
  #9  
Old 09-02-2005, 08:26 PM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
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!

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
High Cloud Storage Demand Allows AWS to Lower Amazon S3 Prices Web Hosting News 2012-02-07 11:16:47
Linux Vendor Red Hat Slips into the OpenStack Cloud Community Web Hosting News 2012-02-01 16:14:58
AWS Storage Gateway Connects On-Premise Appliances to the Cloud Web Hosting News 2012-01-25 16:53:57
Global Switch Sees Outage at Sydney Data Center After Fire Trip Activation Web Hosting News 2011-07-15 19:42:21
Amazon EC2 Hosting Now Runs Red Hat Enterprise Linux Web Hosting News 2011-06-23 14:48:05


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?