Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Read XML file Using PHP

Friday, Jan 27, 2017

Tags:- PHP

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.

Read XML File Using PHP

To Read XML File It Takes Only One Step:-

  1. 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

<div id="wrapper">

$xml = <<<XML
  <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" />

$employees = new SimpleXMLElement($xml);
foreach($employees as $employee)
 echo $employees['name'], "\n";
 echo $employees['age'], "\n";
 echo $employees['salary'], "\n";
 echo "<br><br>";


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.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH