SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reading an RSS feed with PHP

    Hello,

    What's the best way to retrieve an RSS feed (v.2.0) with php and develop a custom display for it?

    Thanks,
    Chris S.
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I learned about magpieRss a while back on these forums.
    Here's the link:
    http://sourceforge.net/project/showf...group_id=55691

    --ed

  3. #3
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Ed, I did see that, but it looked like it only supported up to v.1.0. Is it different now?

    Chris
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  4. #4
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ashattuc
    Thanks, Ed, I did see that, but it looked like it only supported up to v.1.0. Is it different now?

    Chris
    I don't know about that.

    --ed

  5. #5
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I had read the documentation a little further, it says "limited 2.0 support."

    Ed, would you mind showing me some example code of how you implemented MagPie on a web page? I am having a hard time getting it functioning. I'm using the example included with the page:

    PHP Code:
     <html>
      <head>
      <body>
     <?php
          
    require_once("/inc/rss_fetch.inc");
          
    $url $_GET['www.sitepoint.com/rss.php'];
          
    $rss fetch_rss$url );
          
          echo 
    "Channel Title: " $rss->channel['title'] . "<p>";
          echo 
    "<ul>";
          foreach (
    $rss->items as $item) {
              
    $href $item['link'];
              
    $title $item['title'];
              echo 
    "<li>[url="http://$href"]$title[/url]";
          
    }
          echo 
    "</ul>";
      
    ?>
      </body>
      </html>
    And it's coming up with a couple errors:

    Warning: MagpieRSS: fetch_rss called without a url in c:\my documents\ibd\websites\risksecure\inc\rss_fetch.inc on line 231
    Channel Title:

    Warning: Invalid argument supplied for foreach() in c:\my documents\ibd\websites\risksecure\index.php on line 10


    I'd just like to see a working example, if oyu have one.

    Thanks,
    Chris S.
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  6. #6
    SitePoint Wizard Dangermouse's Avatar
    Join Date
    Oct 2003
    Posts
    1,024
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $url = "www.sitepoint.com/rss.php"
    $rss = fetch_rss($url);


  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Wouldn't it just be easier (or at least more maintainable) to create an XSL stylesheet to transform the RSS into HTML, then transform using PHP and send the output to the browser?

  8. #8
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed the require tag to include, and ditched the $_GET[] part of the variable, since I wasn't actually retrieving it from a form, and now it works. It there anything wrong with this solution?

    Thanks,
    Chris

    PHP Code:
    <html>
    <head>
    <body>    
     <?php
         
    include("rss_fetch.inc");
        
    $url 'http://www.securityfocus.com/rss/vulnerabilities.xml';
        
    $rss fetch_rss$url );
        
        echo 
    "Channel Title: " $rss->channel['title'] . "<p>";
        echo 
    "<ul>";
        foreach (
    $rss->items as $item) {
            
    $href $item['link'];
            
    $title $item['title'];
            echo 
    "<li>[url="$href"]$title[/url]";
        }
        echo 
    "</ul>";
    ?>
    </body>
    </html>
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  9. #9
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinnie,

    That kind of sounds what I'd be looking for, but I haven't found a good working example of how to implement that. I will be displaying a feed from another site, will the XSL stylesheet still work for that?

    Thank you,
    Chris
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  10. #10
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by ashattuc
    Vinnie,

    That kind of sounds what I'd be looking for, but I haven't found a good working example of how to implement that. I will be displaying a feed from another site, will the XSL stylesheet still work for that?
    If you know what format the XML tags will be in, it doesn't matter where the XML file is.

  11. #11
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    I was gonna post some code, but mine looks almost just like yours ashattuc, just a different feed, and my links open in a new window.
    It must of been taken from the magpieRss examples or something.

    --ed

  12. #12
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vinnie,

    Do you possibly have a simple working example I can grab the concepts from?

    Thanks,
    Chris
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  13. #13
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have found some good information on how to use an XSL stylesheet to parse an XML document, but I have a question:

    How do you do that server-side with PHP?

    Thank you,
    Chris
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  14. #14
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Use PHP's XSLT functions.

    http://www.php.net/manual/en/ref.xslt.php

    Note: this extension is not installed by default either in Win32 or Unix. Installation instructions are available at the above location.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  15. #15
    SitePoint Zealot hpnadig's Avatar
    Join Date
    Sep 2003
    Location
    Bangalore
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    magpie's a nice script. makes readign rss a lot easier
    Home Page| Blog | Gallery
    sys op & contributor @ kn wikipedia

    Still stuck with a stinky browser? Go get FireFox


Bookmarks

Posting Permissions

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