11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 20 • WEB SERVICESwww.it-ebooks.info• Line 09 identifies the location where the cached feeds will be managed.SimplePie supports feed caching, which boosts performance by reducing theneed to retrieve an RSS feed every time it’s requested. Note that caching isenabled by default, but you’ll need to create the directory where the feeds willbe cached, making sure that the web server daemon owner is able to write tothis directory.• Line 11 passes the feed to the SimplePie object, which is subsequently parsedwhen the init() method is called (line 13).• Line 17 outputs the feed’s title and description.• Lines 20-28 loop through each item in the feed, returning the entry title, URL,description, and publication date.Execute this script and you should see output similar to that shown in Figure 20-3.Figure 20-3. Parsing the WJGilmore.com RSS FeedParsing Multiple FeedsSimplePie also supports the ability to retrieve and sort multiple feeds, creating aggregated output similarto that found when using an aggregator such as Google Reader. This allows you to simultaneouslypublish a variety of feeds within a single consolidated list. The best part of this feature is that you use itexactly as you would when parsing a single feed, except that you instead pass an array of feeds to theset_feed_url() method. For instance, the following example will sort and consolidate feed entries fromthree of my favorite websites:418

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!