Extract XML Response in PHP Example

Rate this post

Today, We want to share with you Extract XML Response in PHP Example.In this post we will show you Parse XML Response in PHP Example, hear for Interprets a string of XML into an object we will give you demo and example for implement.In this post, we will learn about Parsing SOAP responses with PHP’s SimpleXML with an example.

Extract XML Response in PHP Example

There are the Following The simple About Extract XML Response in PHP Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop php xml to json with attributes, so the xml to json php manually for this example is following below.

Free Live Chat for Any Issue

XML File

simple XML structured string

Read Also:  jQuery Ajax Call to Laravel Script with JSON Return

properly formatted XML

<?xml version='1.0'?>
    <website>Pakainfo.com Blog</website>
    <createdby>Jaydeep Gondaliya</createdby>

PHP Convert XML Response

PHP string variable called $xmlResponse

simplexml_load_string i PHP

$xml = simplexml_load_string($xmlResponse);

creating an array of our devlopers

PHP Create An Array

$devlopers = array();
foreach($xml->devlopers as $devloper) {
    $devloperObject = array(
        "adminusername" => $devloper->adminusername,
        "superadmin" => $devloper->superadmin
    array_push($devlopers, $devloperObject);

add the devlopers array to a custom object

$jsonObject = array(
    "website" => $xml->website,
    "createdby" => $xml->createdby,
    "devlopers" => $devlopers

PHP converting simple custom object using the Add to Json methods

Read Also:  php parse XML File SimpleXML


You can following onther way to PHP Convert XML to JSON

Parse An XML Response With PHP

JSON result of our XML response

Response For JSON

  "website": "Pakainfo.com Blog",
  "createdby": "Jaydeep Gondaliya",
  "devlopers": [
      "adminusername": "Jaydeep",
      "superadmin": "Gondaliya"
      "adminusername": "Astha",
      "superadmin": "Bhanderi"

Angular 6 CRUD Operations Application Tutorials

Read :


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


I hope you get an idea about Extract XML Response in PHP Example.
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.