SimplePie 1.5 is now available!

SimplePie Documentation.  Learn how to use this thing.  It's way better than going to school.

You are here: Documentation » API Reference » SimplePie

Differences

This shows you the differences between two versions of the page.

reference:simplepie:start [2007/08/16 20:31]
admin Added information about multifeeds
reference:simplepie:start [2011/11/29 22:16] (current)
sab old revision restored
Line 6: Line 6:
  
 Creates a new SimplePie object, optionally setting various settings (see their specific pages for more detail). 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 [[faq:typical_multifeed_gotchas]] for notes on common issues.**
  
 ===== Parameters ===== ===== Parameters =====
-==== feed_url ==== 
-Set the feed URL(s) (like calling [[reference:SimplePie:set_feed_url]]), and initialise the feed (like [[reference:SimplePie:init]]). 
  
-==== cache_location ==== +==== SimplePie <1.3 ==== 
-Set the cache location (like calling [[reference:SimplePie:set_cache_location]]).+=== feed_url === 
 +Set the feed URL(s) (like calling [[reference:SimplePie:set_feed_url]]), and initialise the feed (like [[reference:SimplePie:init]]). Deprecated.
  
-==== cache_duration ==== +=== cache_location ==
-Set the cache duration (like calling [[reference:SimplePie:set_cache_duration]]).+Set the cache location (like calling [[reference:SimplePie:set_cache_location]]). Deprecated. 
 + 
 +=== cache_duration === 
 +Set the cache duration (like calling [[reference:SimplePie:set_cache_duration]]). Deprecated. 
 +==== SimplePie 1.3+ ==== 
 +None. Parameters were removed to avoid common support issues.
  
 ===== Examples ===== ===== Examples =====
-==== Create object and initialise separately ==== +==== Shorthand syntax ==== 
-This is useful when you have to set additional configuration options.+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 [[reference:simplepie: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. 
 <code php>// Single feed <code php>// Single feed
-$feed = new SimplePie(); +$feed = new SimplePie('http://simplepie.org/blog/feed/'$_SERVER['DOCUMENT_ROOT'] . '/cache');
-$feed->set_feed_url('http://simplepie.org/blog/feed/'); +
-$feed->init();+
 echo $feed->get_title();</code> echo $feed->get_title();</code>
  
 <code php>// Multiple feeds <code php>// Multiple feeds
-$feed = new SimplePie(); +$feed = new SimplePie(array(
-$feed->set_feed_url(array(+
  'http://simplepie.org/blog/feed/',  'http://simplepie.org/blog/feed/',
  'http://digg.com'  'http://digg.com'
-)); +)$_SERVER['DOCUMENT_ROOT'] . '/cache');
-$feed->init();+
 echo $feed->get_title();</code> echo $feed->get_title();</code>
  
-==== Create object and initialise at once ==== + 
-This is handy for just passing in a URL and cache settings.+==== 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 [[reference:SimplePie: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. 
 <code php>// Single feed <code php>// Single feed
-$feed = new SimplePie('http://simplepie.org/blog/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();</code> echo $feed->get_title();</code>
  
 <code php>// Multiple feeds <code php>// Multiple feeds
-$feed = new SimplePie(array(+$feed = new SimplePie(); 
 +$feed->set_feed_url(array(
  'http://simplepie.org/blog/feed/',  'http://simplepie.org/blog/feed/',
  'http://digg.com'  'http://digg.com'
 )); ));
 +$feed->enable_order_by_date(false);
 +$feed->set_cache_location($_SERVER['DOCUMENT_ROOT'] . '/cache');
 +$feed->init();
 echo $feed->get_title();</code> echo $feed->get_title();</code>
  
-===== See Also ===== +==== Absolutely, totally, and completely wrong under any and all circumstances ==== 
-  * [[reference:SimplePie:set_feed_url]] +(We've gotten lots of support questions recently regarding problems when using SimplePie, and most of them stem from the following.) 
-  * [[reference:SimplePie:init]] + 
-  * [[reference:SimplePie:set_cache_location]] +If you pass a URL into the ''SimplePie()'' constructor, it automatically calls [[reference:simplepie: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
-  * [[reference:SimplePie:set_cache_duration]]+  - 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. 
 + 
 +<code php> 
 +$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(); 
 +</code>
  
 {{alphaindex>reference:SimplePie}} {{alphaindex>reference:SimplePie}}

reference/simplepie/start.txt · Last modified: 2011/11/29 22:16 by sab