Use PHP to display any RSS feed on your site Sep18 '07
Over the years, I've struggled with ways to include external content on this site, without having to use JavaScript or Flash "widgets," which are convenient but can be troublesome.
I even got philosophical and preached that external content should remain external - relative to it's domain.
Despite all this, occasionally I'll want to display some content from another site, such as my Twitter updates, or my Google Reader Shared links.
With PHP 5, it's very easy to include external content onto your site. This tutorial will explain how to display the contents of an RSS feed directly into your site's HTML markup.
The benefits of parsing external content are:
- You're not stuck with whatever "badge" or "widget" they provide you, which is often hard to customize to match your own site's design and layout.
- The content you display is accessible by search engines, since it actually becomes part of your site, helping to increase relevancy and page-rank. ("Widget content" is often invisible to search engines.)
- Page loading speed is not affected.
RSS feed
First, find the RSS feed URL for the content you'd like displayed on your site. For this example, we'll use my latest Twitter updates RSS feed:
http://twitter.com/statuses/user_timeline/122933.rss
Below is an example "node" of this RSS feed:
PHP
With PHP, we can parse this information, and display it in a format more comfortable to us, such as a list item:
- Matthom: I've come to the conclusion there is no one-stop-shop browser.
Using basic cURL syntax, we'll loop through each <item> element from the RSS feed, and display it as an HTML unordered list:
Result
This code will loop through each RSS feed <item>, and output my last ten Twitter updates as an HTML unordered list:
- Matthom: I've come to the conclusion there is no one-stop-shop browser.
- Matthom: At the iTunes store.
- Matthom: @MattsShell - We should go to Jewel and pick some up.
- Matthom: Collective Soul - Georgia Girl
- Matthom: woo chilly!
- Matthom: Suppose to be 85 so am wearing shorts again
- Matthom: heading out the door.
- Matthom: I need to start buying some frozen lunch meals
- Matthom: Is it only Tuesday?
- Matthom: Going to eat. Tacos!
Nice, clean, and looks like it comes straight from my own database.
Other resources
- Paul Stamatiou: How To: Parse XML with PHP5.
Categories: Code
, PHP
, RSS
, Tutorials
, Web Development
, XML ![]()
Add Feedback (view all)
Leave feedback
I'm not too familiar with PHP, just messed around with some real basic stuff. I added your code to my page, but am getting an error - call to undef ... Read more.
It would be awsome if it worked. ... Read more.
If you're having trouble getting this to work with your not-twitter RSS feed, adjust the line foreach ( $xmlObjTwitter -> item as $item ) I ... Read more.
Thanks you Jon! That worked great. ... Read more.
Very helpful, thanks! ... Read more.
matthom
is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago.
Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.
Similar Entries
- Digg will eventually replace my RSS subscriptions (5 recent visits)
- Grouping RSS feeds by priority and frequency (43 recent visits)
- RSS thoughts: Categories and Summaries (4 recent visits)
- More on my XML/RSS feeds not rendering (93 recent visits)
- RSS image element dimensions (47 recent visits)
- Concept: release content to RSS first (4 recent visits)
Stats
2178 unique visits since August 2008
Recent Referrers (click)
- display a feed with php
- PHP RSS-feed display
- PHP RSS-feed display
- PHP RSS-feed display
- how to display rss in php
- php rss display
- display rss in php page
- Using PHP to Display RSS
- How to display RSS feed using PHP
- How to display RSS feed using PHP
- using php to display rss
- using php to display rss
- using php to display rss
- php parse rss feed twitter
- php external format pubdate rss
- php external format pubdate rss
- php display rss feed
Hi, I'm trying your method within a TextPattern istallation - therefore between ~ and getting the following error: Par ... Read more.