Extensible Markup Language (XML) is a simple, very flexible text format it is also playing an
increasingly important role in the exchange of a wide variety of data on the Web and elsewhere.
In this tutorial we will show you how to read XML file using PHP.You may also like read and write csv file using PHP.
To Read XML File It Takes Only One Step:-
- Make a PHP file to read xml
Step 1. Make a PHP file to read xml
We make a PHP file and save it with a name read_xml.php
<html> <body> <div id="wrapper"> <?php $xml = <<<XML <employee> <employee name="Amar" age="29" salary="25000" /> <employee name="Rahul" age="22" salary="18000" /> <employee name="Aarti" age="31" salary="40000" /> <employee name="Pooja" age="27" salary="27000" /> <employee name="Manoj" age="34" salary="31000" /> <employee name="Shivam" age="24" salary="20000" /> <employee name="Preeti" age="30" salary="18000" /> </employee> XML; $employees = new SimpleXMLElement($xml); foreach($employees as $employee) { echo $employees['name'], "\n"; echo $employees['age'], "\n"; echo $employees['salary'], "\n"; echo "<br><br>"; } ?> </div> </body> </html>
In this step we write some sample XML data related to employee details like name, age and salary and after that we use SimpleXMLElement function to read xml file and create an object of that to read XML
variable and display them using for each loop.
You may also like create xml sitemap using PHP.
That's all, this is how to import excel file data into mysql database using PHP. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery