easy!

$xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode(array = json_decode($json,TRUE);
Answer from user1398287 on Stack Overflow

easy!

$xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
$json = json_encode(array = json_decode($json,TRUE);
Answer from user1398287 on Stack Overflow
🌐
PHP
php.net › manual › en › book.simplexml.php
PHP: SimpleXML - Manual
For example, this does not work: $xml = new SimpleXMLElement($page); $country = $xml->Response->Placemark->AddressDetails->Country->CountryNameCode; $_SESSION['country'] = $country; This will work: $_SESSION['country'] = (string) $country; ... Here ...
🌐
Packagist
packagist.org › packages › mtownsend › xml-to-array
mtownsend/xml-to-array - Packagist.org
$xml = <<<XML <?xml version="1.0"?> <request> <carrier>fedex</carrier> <id>123</id> <tracking_number>9205590164917312751089</tracking_number> </request> XML; $array = xml_to_array($xml); // $array is: [ 'carrier' => 'fedex', 'id' => '123', 'tracking_number' => '9205590164917312751089' ]; ... ...
🌐
GitHub
github.com › clearstream › xml-to-array
GitHub - clearstream/xml-to-array: Incredibly simple XML to array PHP converter
use Clearstream\XmlToArray\XmlToArray; ... <cdata><![CDATA[<sender>John Doe</sender>]]></cdata> </response> XML; $array = XmlToArray::convert($xml);...
Author   clearstream
🌐
GitHub
github.com › spatie › array-to-xml
GitHub - spatie/array-to-xml: A simple class to convert an array to xml · GitHub
The string to be rendered as the XML tag. ... A unique string that avoids overwriting of duplicate keys in PHP arrays.
Starred by 1.2K users
Forked by 214 users
Languages   PHP
🌐
GitHub
github.com › mtownsend5512 › xml-to-array
GitHub - mtownsend5512/xml-to-array: Easily convert valid xml to a php array.
$xml = <<<XML <?xml version="1.0"?> <request> <carrier>fedex</carrier> <id>123</id> <tracking_number>9205590164917312751089</tracking_number> </request> XML; $array = xml_to_array($xml); // $array is: [ 'carrier' => 'fedex', 'id' => '123', ...
Starred by 117 users
Forked by 14 users
Languages   PHP 100.0% | PHP 100.0%
Find elsewhere
🌐
EDUCBA
educba.com › home › software development › software development tutorials › php tutorial › php xml into array
PHP XML into Array | Working of the PHP XML Into Array
July 3, 2023 - Finally, use the json_decode() function to decode the json string, which converts the json encoded string into an array. Example to load an XML file and convert it into a PHP array –
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
GitHub
github.com › vyuldashev › xml-to-array
GitHub - vyuldashev/xml-to-array: A simple class to convert an xml to array
use Vyuldashev\XmlToArray\XmlToArray; $xml = '<items> <good_guy> <name>Luke Skywalker</name> <weapon>Lightsaber</weapon> </good_guy> <bad_guy> <name>Sauron</name> <weapon>Evil Eye</weapon> </bad_guy> </items>'; $result = XmlToArray::convert($xml); After running this piece of code $result will contain: array:1 [ "items" => array:2 [ "good_guy" => array:2 [ "name" => "Luke Skywalker" "weapon" => "Lightsaber" ] "bad_guy" => array:2 [ "name" => "Sauron" "weapon" => "Evil Eye" ] ] ]
Starred by 36 users
Forked by 15 users
Languages   PHP 100.0% | PHP 100.0%
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-convert-xml-file-into-array-in-php
How to convert XML file into array in PHP? - GeeksforGeeks
July 11, 2025 - json_decode() function: The json_decode() function is used to decode a JSON string. It converts a JSON encoded string into a PHP variable. Step 1: Creating an XML file (Optional): Create an XML file which need to convert into the array.
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-xml-file-into-array-in-php
How to convert XML file into array in PHP?
June 29, 2020 - After the above step, we can use json_encode() function to present the object in the json encoded string. The json_decode() function decode a JSON string. It converts a JSON encoded string into a PHP array. <?php // xml file path $path = "abc.xml"; $xmlfile = file_get_contents($path); $new ...
🌐
LIVEcommunity
live.paloaltonetworks.com › t5 › automation-api-discussions › php-xml-to-array › td-p › 20185
LIVEcommunity - PHP - XML to Array - LIVEcommunity - 20185
April 3, 2015 - So I've been working with the API pretty frequently and have run into a bit of a snag that has caught me now a few times. I'm using CURL with PHP to interact and whenever I get a response, I do a conversion as such: $xmlarr = json_decode(json_encode((array)simplexml_load_string($result)),1); This...
🌐
W3Schools
w3schools.com › php › func_xml_parse_into_struct.asp
PHP xml_parse_into_struct() Function
Index array - containing pointers to the location of the values in the Value array · xml_parse_into_struct(parser, data, values, index) ❮ PHP XML Parser Reference · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS ·
🌐
Linux Hint
linuxhint.com › xml_to_associative_array_in_php
Convert XML to Associative Array in PHP
November 7, 2020 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Adsar
adsar.co.uk › xml-to-array-php
XML to Arrays in PHP - adsar
function xml2array($xml, $flattenValues=true, $flattenAttributes = true, $flattenChildren=true, $valueKey='@value', $attributesKey='@attributes', $childrenKey='@children') { $return = array(); if (!($xml instanceof SimpleXMLElement)) { return $return; } $name = $xml->getName(); $_value = trim((string) $xml); if (strlen($_value) == 0) { $_value = null; }; if ($_value !== null) { if (!$flattenValues) { $return[$valueKey] = $_value; } else { $return = $_value; } } $children = array(); $first = true; foreach ($xml->children() as $elementName => $child) { $value = xml2array($child, $flattenValues,
🌐
Table Convert
tableconvert.com › home › convert xml to php array online
Convert XML to PHP Array Online - Table Convert
January 11, 2019 - The tool automatically parses XML structure and converts it to table format, supporting namespace, attribute handling, and complex nested structures. ... Edit data using our advanced online table editor with professional features. Supports deleting empty rows, removing duplicates, data transposition, sorting, regex find & replace, and real-time preview. All changes automatically convert to PHP format with precise, reliable results. ... Generate standard PHP array code that can be directly used in PHP projects, supporting associative and indexed array formats.