Home > Article > Backend Development > How to parse xml to array in php
php
php parses xml and converts it into an array
php parses xml data and converts it into an array. Use simplexml_load_string() to convert the xml object, json_encode() to convert the object to json, and json_decode() to convert it to an array.
simplexml_load_file() Load xml url
simplexml_load_string() Load xml string
<?php $xml = '<?xml version="1.0" encoding="utf-8"?> <res> <name>test</name> <age>10</age> <sex>man</sex> </res>'; $xml =simplexml_load_string($xml); //xml转object $xml= json_encode($xml); //objecct转json $xml=json_decode($xml,true); //json转array var_dump($xml);
Recommended tutorial: "php tutorial"
The above is the detailed content of How to parse xml to array in php. For more information, please follow other related articles on the PHP Chinese website!