Displaying RSS And Atom Feeds On Your Web Site With SimplePie
Displaying RSS And Atom Feeds On Your Web Site With SimplePieVersion 1.0 SimplePie is a PHP library that can fetch, cache, parse, and normalize RSS and Atom feeds. It allows you to display the newest articles from websites with RSS or Atom feeds on your own site. This is a great way to add new, fresh, and relevant information to your site. This guide shows how you can set it up for your own web site. This document comes without warranty of any kind! I do not issue any guarantee that this will work for you!
1 Preliminary NoteThis tutorial assumes that you have shell access to the server. If you don't, you can easily do all the steps here with the help of an FTP client as well. I'm using an Apache2 web server (Debian Etch) here where PHP5 is already installed. If you still need to set up Apache and PHP on your server, you can refer to the Apache section of the appropriate "Perfect Server" or "Perfect Setup" tutorial for your distribution here on HowtoForge (use the search function to find that tutorial). On Debian Etch, this command will set up Apache2 with PHP5: apt-get install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-idn php-pear php5-imagick php5-imap php5-json php5-mcrypt php5-memcache php5-mhash php5-ming php5-mysql php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl I'm using the web site www.example.com here with the document root /var/www/web1/web; that web site belongs to the user web1_falko and the group web1. The requirements of SimplePie are listed on http://simplepie.org/wiki/setup/requirements. To check if your server fulfills the requirements, create a phpinfo() file: vi /var/www/web1/web/info.php
Call that file in a browser (http://www.example.com/info.php) and check if all required PHP modules are enabled (XML, PCRE, mbstring, cURL, Zlib):
2 SimplePie SetupI want to set up SimplePie in a subdirectory of my document root /var/www/web1/web called simplepie so I create it as follows (together with a cache directory that SimplePie needs for caching feeds): mkdir /var/www/web1/web/simplepie Then I change the ownership of the simplepie directory and its subdirectories and make the cache directory world-writable: cd /var/www/web1/web/ Next I download SimplePie to the /var/www/web1 directory (make sure you grab the latest version from http://simplepie.org/downloads/?download): cd /var/www/web1 To unpack it, we need the unzip tool. If it's not installed, install it now (on Debian/Ubuntu, you can do it as follows: apt-get install unzip ) Now let's unzip SimplePie and move the contents of the package to our /var/www/web1/web/simplepie directory: unzip simplepie_1.1.1.zip The compatibility_test directory contains a test to check if your server fulfills all requirements - basically what we've done with the phpinfo() function already in chapter 1. The demo directory contains a working SimplePie demo (it uses its own cache directory therefore we must make this world-writable as well). The only file we actually need to run SimplePie is simplepie.inc - that's the SimplePie library. Let's remove the SimplePie directory and zip file afterwards to clean up our system: cd .. SimplePie is now set up and ready to be used.
3 SimplePie TestrunDirect your browser to http://www.example.com/simplepie/demo/. You should see the SimplePie demo then. At the bottom of the page there's a link that says SimplePie Compatibility Test (http://www.example.com/simplepie/compatibility_test/sp_compatibility_test.php) - click on that link: The test shows you if all requirements are fulfilled: Let's go back to http://www.example.com/simplepie/demo/ and fill in the URL of a feed (e.g. the HowtoForge RSS feed): On the next page SimplePie displays that feed:
4 Write Your Own PHP Script To Display RSS/Atom Feeds on your Web Sitehttp://simplepie.org/wiki/setup/sample_page has some sample PHP scripts for displaying RSS feeds on your web site. I use the first one here and create the file /var/www/web1/web/feedreader.php: vi /var/www/web1/web/feedreader.php I have to modify that script a little bit because I have to set the correct cache location (by adding it to the $feed = new SimplePie() constructor), therefore that script looks as follows:
Let's call that script in a browser (http://www.example.com/feedreader.php), and the output should look like this: Now you can modify the script or write your own scripts. You can find the SimplePie function reference here: http://simplepie.org/wiki/reference/start A few SimplePie tutorials can be found on http://simplepie.org/wiki/tutorial/start.
5 Links
|









Recent comments
19 hours 6 min ago
20 hours 15 min ago
22 hours 8 min ago
23 hours 8 min ago
23 hours 22 min ago
1 day 2 hours ago
1 day 4 hours ago
1 day 5 hours ago
1 day 20 hours ago
2 days 12 hours ago