Home

Bio
My Articles
Blog
Photo albums
Contact me

IT news
Articles


Take news/content from other sites using RSS

16 Jan 2007, 1302 read(s)
Tags:


Pages: 1 2 3

A simple PHP way of parsing RSS feeds and showing news from other sites on your own website. A step-by-step tutorials for dummies.

P.S. This is a "quick-written" article. It has not been finished yet! It should be written a little bit more detailted, but that will happen in a few days.

Definition of terms

XML (Extensible Markup Language) is a W3C initiative that allows information and services to be encoded with meaningful structure and semantics that computers and humans can understand. XML is great for information exchange, and can easily be extended to include user-specified and industry-specified tags.
A web feed is a data format used for serving users frequently updated content. Content distributors syndicate a web feed, thereby allowing users to subscribe to it. Most of the web feeds use XML as a way and structure of exchaning information.
RSS is a XML-based family of web feed formats used to publish frequently updated digital content, such as blogs, news feeds or podcasts.
I recommend you to read some more information about RSS, XML and web feeds in order to fully understand this article.


RSS files explanation

Most of the modern websites that have news or other kind of dynamically updated content in them allow users to use these feeds. The feed is a simple file, structured in XML. This file should be parsed by our PHP script so that the script "understands" the kind of information inside this file - which part is an item (an item might be a news, article or some other kind of information) is the title, which one - the body, images, links and whatever else is contained there in the RSS file.

Our script

We need to parse the general structure of the XML file. RSS is actually a XML-based file so ... we will need some PHP functions to read and split in arrays a whole XML file. Of course, we can write the code to preform this task, but why doing it and loose time when there are free scripts and classes doing that pretty well. I searched the web for such scripts and found out a variety of them. Unfortunately, neither of them worked as I expected. Some were pretty simple, others were too complex. The one I liked most was called LastRSS. It worked well, but now actually the way I needed it. However, I applied some modifications and made it work the way I wanted. Now, using this file and some basic PHP knowledge, I will show you how to parse RSS files and use the content in your website.

Download script

You should first download the lastRSS.php file. Not the one originally published in the author's website, but the one I have modified. Otherwise, it may not work the same way and unexpected problems/erros my occur.


Pages: 1 2 3

Comments

Anonymous: samo edna zabelejka, s toq cache_time=3600 osigurqvash refresh na RSSa prez edin 4as, tova dobre, nqma da uveli4ish mnogo trafika na stranicata si, oba4e predstavi si 4e v ramkite na dva dni ne se poqvi novina, tva zna4i da si vkarash edna novina v arhiv4eto okolo 40 puti ako slojish edna funkciika za proverka dali poslednata novina slu4aino ne syvpada s predposlednata, shte si spestish i resursi i eventualni problemi s novinite
Martin Tsarev: Не, тук няма "архив". Функцията addnews просто ти добавя новините в двумерен масив в случай, че искаш да използваш новини от различни източници по-елегантно. Самия скрипт не работи с архив, а просто като свали нова версия на RSS feed-a, използва нея и не помни старите новини. Разбира се, такава функция можеш да си допишеш, но аз лично мисля, че за аматьорски сайт е излишна.
BaCeTo: Мартине, оправи си връзката до lastRSS.php файла. Тази дето си я сложил нещо не бачка, опитах се да сваля файла и да го разгледам, но само ми отвори празна страничка. Виж някаде си объкал връзката, коригирай я, ако обичаш
Anonymous:
Anonymous:
Anonymous:
Anonymous:
Anonymous:
Anonymous:
Anonymous:
Anonymous:
Anonymous:

Add comment...