PHP converts XML into an array and a php xml array. PHP converts XML into an array. if you use the xmldataxmlsimplexmlloadstring (data) obtained by curl, data ['TK '] jsondecode (jsonencode (xml), TRUE ); how to Convert XML into an array using PHP directly?
If you use curl to obtain xml data
Xml = simplexmlloadstring (data );
Data ['TK '] = jsondecode (jsonencode (xml), TRUE );
If you directly obtain URL data
Xml = simplexmlloadfile (data );
Data ['TK '] = jsondecode (jsonencode (xml), TRUE );
Convert simplexml to json and then convert json to an array.
Code:
<?php$string = <<
Forty What?
Joe
Jane
I know that's the answer -- but what's the question?
XML;$xml=simplexml_load_string($string);$data = json_decode(json_encode($xml),TRUE);var_dump( $xml );var_dump( $data );
object(SimpleXMLElement)[1] public 'title' => string 'Forty What?' (length=11) public 'from' => string 'Joe' (length=3) public 'to' => string 'Jane' (length=4) public 'body' => string ' I know that's the answer -- but what's the question? ' (length=57)array 'title' => string 'Forty What?' (length=11) 'from' => string 'Joe' (length=3) 'to' => string 'Jane' (length=4) 'body' => string ' I know that's the answer -- but what's the question? ' (length=57)
The above is all the content of this article, hoping to help you learn.
Articles you may be interested in:
- Convert XML to an array in php
- PHP code for converting arrays into XML format
- Php-XML-to-array functions
- PHP detailed explanation of converting XML to array
- In php, the Array2xml class converts arrays into XML instances.
- Php to convert arrays to XML
- Recursive php array-to-xml code sharing
Export if you use curl to obtain xml data xml = simplexmlloadstring (data); data ['TK '] = jsondecode (jsonencode (xml), TRUE...