Chetan Rohilla
Posted on March 8, 2022
A Feeds is an xml file which contains the information about website. For an example xml file of E-Commerce website contains information about products, categories, offers, tags. The data in xml(Extensible Markup Language) file contains in the form of structured tags. In this article, we will learn how to read feeds in php.
Here we will read the xml feeds of our website URL w3courses.org/feed/
<?php
$xml=simplexml_load_file("https://www.w3courses.org/feed/") or die("Error: Cannot create object");
foreach ($xml->channel->item as $key => $value) {
print_r($value);
}
?>
We used the function simplexml_load_file to read the feeds in PHP. SimpleXML is a PHP extension that allows us to easily manipulate and get XML data. Inside the print_r we have the information about item tags.
The SimpleXML Parser in PHP
SimpleXML is a tree-based parser. It provides an easy way of getting an element’s name, attributes and textual content if you know the XML document’s structure or layout.
SimpleXML turns an XML document into a data structure you can iterate through like a collection of arrays and objects.
Compared to DOM or the Expat parser, SimpleXML takes a fewer lines of code to read text data from an element.
Please like share and give positive feedback to motivate me to write more.
For more tutorials visit my website or follow me.
Thanks:)
Happy Coding:)
Posted on March 8, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.