Home » How To Convert XML To Associative Array in PHP

How To Convert XML To Associative Array in PHP

Today, We want to share with you How To Convert XML To Associative Array in PHP.In this post we will show you Parse XML into associative array using PHP, hear for Convert a SimpleXML object to associative array we will give you demo and example for implement.In this post, we will learn about Converting an XML Object to Associative Array in PHP with an example.

How To Convert XML To Associative Array in PHP

There are the Following The simple About How To Convert XML To Associative Array in PHP Full Information With Example and source code.

Read Also:  Convert XML to JSON in PHP

As I will cover this Post with live Working example to develop Convert Array to XML and XML to Array in PHP, so the XML into Associative Array using PHP for this example is following below.

Step 1: Sample XML file

<?xml version='1.0'?>  
    <ptitle name='Mobile'>  
    <ptitle name='Book'>  
	<ptitle name='Assertive'>  

Step 2: PHP Convert sample.xml File Into String

$product_xmlfile = file_get_contents($path);

Step 3: Convert string of XML into an Object

$product_obj= simplexml_load_string($product_xmlfile);

Step 4: PHP Encode XML Object Into JSON

$json  = json_encode($product_obj);

Step 5: PHP Decode Json Object

$results_data = json_decode($json, true);

PHP Full Source Code

$product_xmlfile = file_get_contents($path);
$product_obj= simplexml_load_string($product_xmlfile);
$json  = json_encode($product_obj);
$results_data = json_decode($json, true);

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  How to Open URL in New Tab using Meteor.js


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How To Convert XML To Associative Array in PHP.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Angular 4 Grid with CRUD operations | Angular 4 insert update delete
  2. Read Also:  how to get values from xml object array in php?
  3. Read Also:  How to Create AngularJS UI-Grid Editable - GridView
  4. Read Also:  Extract XML Response in PHP Example
  5. Read Also:  php parse XML File SimpleXML
  6. Read Also:  css disable button
  7. Read Also:  PHP Time Ago Helper Function
  8. Read Also:  Installing laravel on windows wamp xampp
  9. Read Also:  Laravel 5.7 Stripe Payment Gateway Example From Scratch
  10. Read Also:  About prevNext - first‹ prevnext ›last

Leave a Comment

Your email address will not be published. Required fields are marked *