

:)Ģ) For a PopURLs clone using SimplePie, check out NewsBlocks ( )ģ) For the IDN folder, if you load it and include the include inside it, SimplePie will support Internationalized Domain Names.Ĥ) Caching is enabled by default, and writes to ‘./cache’ unless you tell it to write someplace else, and defaults to 1 hour.ĥ) $feed->handle_content_type() deals with the character encoding (e.g. Lastly, it’s important to remember that making things easy is hard.
#Php rss reader tutorial code#
Also, a large portion of that file size is from code comments. Great screencast! Here are a few additional notes for those following along:ġ) No, loading simplepie.inc doesn’t have a big load on the in-browser code, as it all runs on the server. We output the title, link, date, and description.Īnd this is all that is required to read an RSS feed using PHP.This is Ryan from the SImplePie project.

Now we go on to outputting the values through the echo() function. This retrieves the link from the array.įor the $date variable, we get the date by using the strtotime() function to convert the string in the XML RSS feed to a time value that can be formatted in PHP. We then create a variable named $link, which we set equal to $list. This gets the title from the $list array. We then create a PHP variable $title, which we set equal to $list. This is because the articles are from CNN.

We start at the first element (element 0) and go until we have gotten 10 results.Īfter this, we echo out as a header (an h1 tag) CNN Articles. We create a for loop just for the purpose of us being able to loop through each element that was pushed onto the array we've created, $list. This is the number of results we show from the RSS feed. Next, we create a variable named $numberofresults. This portion of the code ends when we've gone through each item in the RSS feed. Inside of this function, we pass the tag that we want to retrieve.įor each item in the RSS feed, we add it to the array $list via the array_push() function. We get the values of these tags through the getElementsByTagName() function. To the article, and the date the article was published. We assign these respectively to the title of the article, the description of the article, the hyperlin We have 4 names or properties in this associative array: title, descript, link, and date. The array $list will be an associative array, that is an array composed of name/value pairs or property/value pairs. Variables which holds represents the entire RSS feed as a document object model. We loop through each item in the RSS feed for a given site through the foreach loop. This will hold all of the items in the RSS feed (an item represents an article on that website). This is the RSS feed for the technology section of the CNN website. The $rss variable loads the CNN tech RSS feed. So the $rss variable simulates a DomDocument. The PHP code to search an RSS feed for any keyword is shown below. Instead, through subscription to the RSS feed, a user can automatically know, through the RSS feed, when thereīesides subscribiing to an RSS feed, another way to do it is to create a PHP program that reads an RSS feed. So a user doesn't have to visit the site to see Users who are subscribed to the RSS feed then get fed this new updated content. When a website creates an RSS feed, it puts the contents of the new articles that it publishes on the RSS feed, such as theĪrticle title, the link to the article, the publication date, and so on. If you look up the definition for syndication, it means the supply or broadcast content. RSS stands for Really Simple Syndication. So RSS feeds are a way that a website has of sharing information that can be used by the rest of the internet to see what new

#Php rss reader tutorial how to#
In this article, we show how to read an RSS feed using PHP.
