How to Read RSS Feed in PHP
Posted on: March 06, 2021 by Ariessa Norramli
In this article, you will learn how to read an RSS feed in PHP. RSS stands for Really Simple Syndication and it is a web feed that allows subscribers to get updates from multiple websites on a single page.
Read RSS Feed
In order to read an RSS feed, you can use the file_get_contents()
method andSimpleXMLElement()
method.
$content = file_get_contents("https://feeds.feedburner.com/phpclassesblog-xml");
// Instantiate XML element
$a = new SimpleXMLElement($content);
echo "<ul>";
foreach($a->channel->item as $entry) {
echo "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
}
echo "</ul>";
Note: The file_get_contents()
method functions by reading the content of a file into a string. The SimpleXMLElement()
method functions by representing an XML element.
Share on social media
//