php xml to array - Web Development and Web Design Codes


Saturday, April 21, 2018

php xml to array

php xml to array
php xml to array
php xml to array
Hi Friends in this lesson we are going to learn how to convert xml file into array using php..
this is very simple codes to convert php xml to array..

create xml file: file.xml
<?xml version="1.0"?>
  <title>Users Information</title>
      <name>ANJAN KUMAR</name>
      <name>Palash Mondal</name>
	  <education>Computer Science</education>
      <name>Nikita Adikary</name>
	  <education>Software Engineering</education>

Create php file to access xml file: xml_to_array.php
//xml file path
$path = "file.xml";
//read entire file into string
$xmlfile = file_get_contents($path);
//convert xml string into an object
$xml = simplexml_load_string($xmlfile);
$json  = json_encode($xml);
//convert into associative array
$xmlArr = json_decode($json, true);

That's it friends how to convert xml to array using php..if you like this post please share with your friends..Thank You..

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.