Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2002
    Location
    York, United Kingdom
    Posts
    279

    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.

  2. #2
    Join Date
    Oct 2002
    Location
    York, United Kingdom
    Posts
    279
    Did anyone find this useful ?

  3. #3
    Join Date
    May 2005
    Location
    Mumbai, India
    Posts
    555
    Works in PHP 5 only - for versions < 5, xml_parse function has to be used.

  4. #4
    is this true? it won't work with PHP4x? How about an example with PHP4x?

    Thanks
    Charles
    <<Please see rules for signature setup>>

  5. #5
    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.

  6. #6
    but my host only has php4 installed....no 5.

    Charles
    <<Please see rules for signature setup>>

  7. #7
    Join Date
    Nov 2004
    Posts
    30
    Thanks a lot.

  8. #8
    Join Date
    May 2005
    Location
    Mumbai, India
    Posts
    555
    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.

  9. #9
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •