Home arrow PHP arrow Page 2 - Web Services: MagpieRSS

How Magpie Parses a Feed - PHP

In this second part of a five-part series on Web Services, you will learn how to install and use MagpieRSS, a popular RSS parser. This article is excerpted from chapter 20 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

TABLE OF CONTENTS:
  1. Web Services: MagpieRSS
  2. How Magpie Parses a Feed
  3. Retrieving and Rendering an RSS Feed
  4. Aggregating Feeds
By: Apress Publishing
Rating: starstarstarstarstar / 1
July 29, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Magpie parses a feed by placing it into an object consisting of four fields:channel,image,items, andtextinput. In turn,channel is an array of associative arrays, while the remaining three are associative arrays. The following script retrieves theblog.xmlfeed, outputting it using theprint_r()statement:

<?php
   
require("magpie/magpie.php");
   
$url = http://localhost/book/20/blog.xml;
    $rss = fetch_rss($url);
   
print_r($rss);
?>

This returns the following output (formatted for readability):

Magpie_Feed Object (
    [items] => Array (
       
[0] => Array(
            [title] => Killer Firefox Tip #294
            [title_detail] => Array (
                [type] => text
               
[value] => Killer Firefox Tip #294
            )
            [link] => http://opensource.apress.com/article/190/
            [links] => Array (
               
[0] => Array (
                    [rel] => alternate [href] =>        
http://opensource.apress.com/article/190/

               
)
            )
           
[author] => W. Jason Gilmore
            [description] => Like most of you, I spend bunches of time
       
downloading large files from the Web,
       typically podcasts and PDF documents...
        )
        [1] => Array (
            [title] => Beginning Ubuntu Linux wins Linux Journal Award!
            [title_detail] => Array (
                [type] => text
               
[value] => Beginning Ubuntu Linux wins Linux Journal Award!
            )
            [link] => http://opensource.apress.com/article/189/
            [links] => Array (
                [0] => Array (
                    [rel] => alternate [
                    href] => http://opensource.apress.com/article/189/
               
)
            )
            [author] => Keir Thomas
            [description] => Woo hoo! My book, Beginning Ubuntu Linux, has
                                 
won an award in the Linux Journal Editor's Choice
                                  2006 awards! More precisely...
        )

        [2] => Array (
            [title] => Forms Validation with CakePHP
            [title_detail] => Array (
                [type] => text
                [value] => Forms Validation with CakePHP
            )
            [link] => http://opensource.apress.com/article/188/
            [links] => Array (
                [0] => Array (
                    [rel] => alternate
                    [href] => http://opensource.apress.com/article/188/
                )
            )
           
[author] => W. Jason Gilmore
            [description] => Neglecting to validate user input is akin to foregoing
                             any defensive gameplan for containing the NFL's
                             leading rusher. Chances are sooner or later...
       
)
    )
    [feed] => Array (
       
[title] => Inside Open Source
        [title_detail] => Array (
            [type] => text
            [value] => Inside Open Source
        )
        [link] => http://opensource.apress.com/
        [links] => Array (
           
[0] => Array (
                [rel] => alternate
                [href] => http:// opensource.apress.com/
           
)
        
)
    )
    [feed_type] =>
    [feed_version] =>
    [_namespaces] => Array ( )
    [from_cache] =>
    [_headers] => Array (
        [date] => Sun, 12 Nov 2006 21:11:12 GMT
        [server] => Apache/2.0.58 (Win32) PHP/5.1.4
        [last-modified] => Sun, 12 Nov 2006 21:10:41 GMT
        [etag] => "ad43-4f5-37c15b77"
        [accept-ranges] => bytes
        [content-length] => 1269
        [connection] => close
        [content-type] => application/xml
   
)
    [_etag] => "ad43-4f5-37c15b77"
    [_last_modified] => Sun, 12 Nov 2006 21:10:41 GMT
    [output_encoding] => utf-8
    [channel] => Array (
        [title] => Inside Open Source
        [title_detail] => Array (
            [type] => text
            [value] => Inside Open Source
        )
        [link] => http://opensource.apress.com/
        [links] => Array (
            [0] => Array (
                [rel] => alternate
                [href] => http://opensource.apress.com/
            )
        )
    )
)

An object namedMagpie_Feedis returned, containing several attributes. This means you can access the feed content and other attributes using standard object-oriented syntax. The following examples demonstrate how the data is peeled from this object and presented in various fashions.



 
 
>>> More PHP Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: