3 <title>Magpie RSS - PHP RSS Parser
</title>
4 <link rel=
"alternate" type=
"application/rss+xml" title=
"RSS"
5 href=
"http://laughingmeme.org/magpierss.rdf" />
8 font-family:trebuchet MS, trebuchet, verdana, arial, sans-serif;
13 pre { font-family:
"Courier New", monospace;
15 margin:
0.2em
2.5em
0.2em
3em;
16 background-color: #efeff5;
17 border:
1px solid #cfcfcf;
25 a.nav { color: #FFFFFF; }
30 border:
2px solid #cfcfcf;
32 background-color: #
996699;
38 <img src=
"magpie-photo.jpg">
41 <h2>MagpieRSS provides an XML-based (expat) RSS parser in PHP.
</h2>
43 MagpieRSS is compatible with RSS
.9 through RSS
1.0, and supports the
44 RSS
1.0's modules. (with a few exceptions)
47 <center><h3>Project Info
</h3></center>
50 href=
"http://sourceforge.net/project/showfiles.php?group_id=55691">Download
53 href=
"http://sourceforge.net/mail/?group_id=55691">Mailing
55 <li><a class=
"nav" href=
"#news">News!
</a></li>
56 <li><a class=
"nav" href=
"#why">Why?
</a></li>
57 <li><a class=
"nav" href=
"#features">Features
</a></li>
58 <li><a class=
"nav" href=
"#philosophy">Philosophy
</a></li>
59 <li><a class=
"nav" href=
"#usage">Usage Examples
</a></li>
60 <li><a class=
"nav" href=
"/cookbook.html">Cookbook
</a></li>
61 <li><a class=
"nav" href=
"#todo">Todo
</a></li>
62 <li style=
"list-style: none; padding-top: 5px;"><a title=
"Keep up on MagpieRSS news via RSS" href=
"http://laughingmeme.org/magpierss.rdf"><img
63 src=
"http://magpierss.sf.net/black_grey_magpie_news.gif" border=
"0"></a></li>
72 href=
"http://sourceforge.net/project/showfiles.php?group_id=55691">MagpieRSS
75 <li> important bugfix!
</li>
76 <li> fix
<a href=
"http://laughingmeme.org/archives/000811.html
77 ">"silent failure"</a> when PHP doesn't have zlib
</li>
83 <a href=
"http://minutillo.com/steve/feedonfeeds/">Feed On Feeds Uses Magpie
</a>
85 <li> server based PHP RSS aggregator built with MagpieRSS
</li>
86 <li> easy to install, easy to use.
</li>
94 href=
"http://sourceforge.net/project/showfiles.php?group_id=55691&release_id=158897">MagpieRSS
97 <li> supports transparent HTTP gzip content negotiation for reduced bandwidth usage
</li>
98 <li> quashed some undefined index notices
</li>
106 href=
"http://sourceforge.net/project/showfiles.php?group_id=55691&release_id=139643">MagpieRSS
109 <li> minor release, more error handling clean up
</li>
110 <li> documentation fixes, simpler example
</li>
111 <li> new
<a href=
"/TROUBLESHOOTING">trouble shooting
</a> guide for installation and usage problems
</a>
118 href=
"http://laughingmeme.org/magpierss.rdf">Magpie News as RSS
</a>
120 <li> releases, bug fixes, releated stories as an RSS feed
</li>
128 href=
"http://magpierss.sourceforge.net/cookbook.html">MagpieRSS
129 Cookbook: Simple PHP RSS How Tos
</a>
131 <li> answers some of the most frequently asked Magpie questions
</li>
132 <li> feedback, suggestions, requests, recipes welcome
</li>
138 <a href=
"http://sourceforge.net/project/showfiles.php?group_id=55691&release_id=134850">MagpieRSS
0.4 Released!
</a>
140 <li> improved error handling, more flexibility for script authors,
141 backwards compatible
</li>
142 <li> new and better examples! including using MagpieRSS and
<a
143 href=
"http://smarty.php.net">Smarty
</a></li>
144 <li> new Smarty plugin for RSS date parsing
</li>
150 <a href="http://www.infinitepenguins.net/rss/">Infinite Penguin now
151 supports Magpie 0.3</a>
153 <li> simple, sophisticated RSS viewer</li>
154 <li> includes auto-generated javascript ticker from RSS feed</li>
162 href="http://traumwind.tierpfad.de/blog/magpie/magpie_alike.php">Traumwind
163 releases REX backend for MagpieRSS</a>
165 <li>drop in support using regex based XML parser</li>
166 <li>parses improperly formed XML that chokes expat</li>
173 href="http://sourceforge.net/project/showfiles.php?group_id=55691&release_id=118652">
174 MagpieRSS 0.3 Released!</a>
176 <li>Support added for
177 <a href="http://fishbowl.pastiche.org/archives/001132.html">HTTP
178 Conditional GETs</a>.</li>
179 <li>See <a href="http://sourceforge.net/project/shownotes.php?group_id=55691&release_id=118652">ChangeLog</a>
183 <li class="news">MagpieRSS 0.2!</a>
185 <li>Major clean up of the code. Easier to use.</li>
186 <li>Simpler install on shared hosts.</li>
187 <li>Better documentation and comments.</li>
190 <li class="news">We've <a href="http://sourceforge.net/projects/magpierss/">moved to
191 Sourceforge!</a></li>
198 I wrote MagpieRSS out of a frustration with the limitations of existing
199 solutions. In particular many of the existing PHP solutions seemed to:
201 <li>use a parser based on regular expressions, making for an inherently
203 <li>only support early versions of RSS
204 <li>discard all the interesting information besides item title, description,
206 <li>not build proper separation between parsing the RSS and displaying it.
208 In particular I failed to find any PHP RSS parsers that could sufficiently
209 parse RSS
1.0 feeds, to be useful on the RSS based event feeds we generate
210 at
<a href=
"http://protest.net">Protest.net
</a>.
213 <a name=
"features"></a>
217 <li class=
"toplevel">
221 require('rss_fetch.inc');
222 $rss = fetch_rss($url);
226 <li class=
"toplevel">
227 <h4>Parses RSS
0.9 - RSS
1.0</h4>
229 Parses most RSS formats, including support for
230 <a href=
"http://www.purl.org/rss/1.0/modules/">1.0 modules
</a> and limited
231 namespace support. RSS is packed into convenient data structures; easy to
232 use in PHP, and appropriate for passing to a templating system, like
233 <a href=
"http://smarty.php.net">Smarty
</a>.
236 <h4>Integrated Object Cache
</h4>
238 Caching the parsed RSS means that the
2nd request is fast, and that
239 including the rss_fetch call in your PHP page won't destroy your performance,
240 and force you to reply on an external cron job. And it happens transparently.
244 <h4>HTTP Conditional GETs
</h4>
246 Save bandwidth and speed up download times with intelligent use of
247 Last-Modified and ETag.
<br /> See
<a
248 href=
"http://fishbowl.pastiche.org/archives/001132.html">HTTP Conditional Get for RSS Hackers
</a>
251 <li><h4>Configurable
</h4>
253 Makes extensive use of constants to allow overriding default behaviour, and
254 installation on shared hosts.
258 <li>rss_fetch.inc - wraps a simple interface (
<code>fetch_rss()
</code>)
260 <li>rss_parse.inc - provides the RSS parser, and the RSS object
261 <li>rss_cache.inc - a simple (no GC) object cache, optimized for RSS objects
262 <li>rss_utils.inc - utility functions for working with RSS. currently
263 provides
<code>parse_w3cdtf()
</code>, for parsing
<a
264 href=
"http://www.w3.org/TR/NOTE-datetime">W3CDTF
</a> into epoch seconds.
271 <a name=
"philosophy"></a>
272 <h3>Magpie's approach to parsing RSS
</h3>
274 Magpie takes a naive, and inclusive approach. Absolutely
275 non-validating, as long as the RSS feed is well formed, Magpie will
276 cheerfully parse new, and never before seen tags in your RSS feeds.
279 This makes it very simple support the varied versions of RSS simply, but
280 forces the consumer of a RSS feed to be cognizant of how it is
281 structured.(at least if you want to do something fancy)
284 Magpie parses a RSS feed into a simple object, with
4 fields:
285 <code>channel
</code>,
<code>items
</code>,
<code>image
</code>, and
286 <code>textinput
</code>.
290 <code>$rss-
>channel
</code> contains key-value pairs of all tags, without
291 nested tags, found between the root tag (
<rdf:RDF
>, or
<rss
>)
292 and the end of the document.
296 <code>$rss-
>items
</code> is an array of associative arrays, each one
297 describing a single item. An example that looks like:
299 <item rdf:
about=
"http://protest.net/NorthEast/calendrome.cgi?span=event&ID=210257">
300 <title
>Weekly Peace Vigil
</title
>
301 <link
>http://protest.net/NorthEast/calendrome.cgi?span=event
&ID=
210257</link
>
302 <description
>Wear a white ribbon
</description
>
303 <dc:subject
>Peace
</dc:subject
>
304 <ev:startdate
>2002-
06-
01T11:
00:
00</ev:startdate
>
305 <ev:location
>Northampton, MA
</ev:location
>
306 <ev:enddate
>2002-
06-
01T12:
00:
00</ev:enddate
>
307 <ev:type
>Protest
</ev:type
>
310 Is parsed, and pushed on the
<code>$rss-
>items
</code> array as:
313 title =
> 'Weekly Peace Vigil',
314 link =
> 'http://protest.net/NorthEast/calendrome.cgi?span=event
&ID=
210257',
315 description =
> 'Wear a white ribbon',
317 subject =
> 'Peace'
320 startdate =
> '
2002-
06-
01T11:
00:
00',
321 enddate =
> '
2002-
06-
01T12:
00:
00',
322 type =
> 'Protest',
323 location =
> 'Northampton, MA'
329 <h4>image and textinput
</h4>
330 <code>$rss-
>image
</code> and
<code>$rss-textinput
</code> are associative arrays
331 including name-value pairs for anything found between the respective parent
336 <h3>Usage Examples:
</h3>
338 A very simple example would be:
340 require_once 'rss_fetch.inc';
342 $url = 'http://magpie.sf.net/samples/imc
.1-
0.rdf';
343 $rss = fetch_rss($url);
345 echo
"Site: ", $rss-
>channel['title'],
"<br>\n";
346 foreach ($rss-
>items as $item ) {
347 $title = $item[title];
349 echo
"<a href=$url>$title</a></li><br>\n";
352 More soon....in the meantime you can check out a
353 <a href=
"http://www.infinitepenguins.net/rss/">cool tool built with
354 MagpieRSS
</a>, version
0.1.
361 <li>Swap in a smarter parser that includes optional
362 support for validation, and required fields.
</li>
364 <li>Support RSS
2.0 (as much as I'm annoyed by it)
</li>
366 <li>Improve support for modules that rely on attributes
</li>
371 <li>Light-weight garbage collection
377 href=
"http://diveintomark.org/archives/2002/08/15.html">auto-detect an
378 RSS feed
</a>, given a URL following, much like
<a
379 href=
"http://diveintomark.org/projects/misc/rssfinder.py.txt">rssfinder.py
</a>does.
384 <li>More examples
</li>
385 <li>A test suite
</li>
386 <li>RSS generation, perhaps with
<a
387 href=
"http://usefulinc.com/rss/rsswriter/">RSSwriter
</a>?
393 <h3>RSS Resources
</h3>
395 <li><a href=
"http://mnot.net/rss/tutorial/">RSS Tutorial for Content Publishers
396 and Webmasters
</a> is a great place to start.
397 <li><a href=
"http://gils.utah.gov/rss/">RSS Workshop: Publish and Syndicate
398 Your News to the Web
</a> is also a good introduction
</li>
399 <li><a href=
"http://www.disobey.com/amphetadesk/finding_more.html">Finding
400 More Channels
</a> on how to find RSS feeds.
401 <li>Hammersley's
<a href=
"http://rss.benhammersley.com/">Content Syndication
402 with XML and RSS
</a> is a blog covering RSS current events.
403 <li><a href=
"http://groups.yahoo.com/group/rss-dev/">RSS-DEV mailing
404 list
</a> is generally a very helpful, informative space, with the occasional
406 <li><a href=
"http://feeds.archive.org/validator/">RSS Validator
</a>
409 <h3>License and Contact Info
</h3>
410 Magpie is distributed under the GPL license...
412 coded by: kellan (at) protest.net, feedback is always appreciated.
414 <a href=
"http://sourceforge.net"><img
415 src=
"http://sourceforge.net/sflogo.php?group_id=55691&type=3"
416 width=
"125" height=
"37" border=
"0" alt=
"SourceForge.net Logo"></a>
417 <img src=
"http://laughingmeme.org/magpie_views.gif">