You are here: Documentation » API Reference » SimplePie
SimplePie
Description
class SimplePie { SimplePie ([string $feed_url], [string $cache_location], [int $cache_duration]) }
Creates a new SimplePie object, optionally setting various settings (see their specific pages for more detail).
There are differences between handling a single feed and merging feeds together with Multifeeds. Read Typical Multifeed Gotchas for notes on common issues.
Parameters
SimplePie <1.3
feed_url
Set the feed URL(s) (like calling set_feed_url()), and initialise the feed (like init()). Deprecated.
cache_location
Set the cache location (like calling set_cache_location()). Deprecated.
cache_duration
Set the cache duration (like calling set_cache_duration()). Deprecated.
SimplePie 1.3+
None. Parameters were removed to avoid common support issues.
Examples
Shorthand syntax
The following is the shorthand syntax, which is geared for the quick setting of url and cache settings with minimal code. Most people never configure much further than this, which is why we have it. Passing values this way automatically calls init() for you. This is no longer available from SimplePie 1.3. The following applies to SimplePie <1.3 only.
The first example is using one feed, while the second shows how to merge multiple feeds together.
// Single feed $feed = new SimplePie('http://simplepie.org/blog/feed/', $_SERVER['DOCUMENT_ROOT'] . '/cache'); echo $feed->get_title();
// Multiple feeds $feed = new SimplePie(array( 'http://simplepie.org/blog/feed/', 'http://digg.com' ), $_SERVER['DOCUMENT_ROOT'] . '/cache'); echo $feed->get_title();
Standard syntax
Next is the standard (long) syntax, which is geared for setting any of the numerous available configuration options for maximum tweaking value. Make sure you follow up your config options by calling init() (like in the example) so that SimplePie knows you're done setting options and are ready to get to business.
Again, the first example is using one feed, while the second shows how to merge multiple feeds together.
// Single feed $feed = new SimplePie(); $feed->set_feed_url('http://simplepie.org/blog/feed/'); $feed->enable_order_by_date(false); $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache'); $feed->init(); echo $feed->get_title();
// Multiple feeds $feed = new SimplePie(); $feed->set_feed_url(array( 'http://simplepie.org/blog/feed/', 'http://digg.com' )); $feed->enable_order_by_date(false); $feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache'); $feed->init(); echo $feed->get_title();
Absolutely, totally, and completely wrong under any and all circumstances
(We've gotten lots of support questions recently regarding problems when using SimplePie, and most of them stem from the following.)
If you pass a URL into the SimplePie()
constructor, it automatically calls init(). Once init() has been called, SimplePie will ignore any new configuration options (because you've already told it that you were done setting them). There are two lessons to learn from this:
- Don't mix-and-match shorthand syntax with standard/long syntax because it won't do what you want.
- If you want to use additional config options, DO NOT USE THE SHORTHAND SYNTAX.
$feed = new SimplePie('http://simplepie.org/blog/feed/'); // This calls init() automatically, and ignores all additional config options. $feed->enable_cache(false); // Ignored. $feed->enable_order_by_date(false); // Ignored. echo $feed->get_title();
reference/simplepie/start.txt · Last modified: 2011/11/29 22:16 by sab