This article describes in detail how PHP converts XML into an array. if you are interested, refer to the xml data obtained using curl.
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:
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.
For more articles about how PHP converts XML into arrays, refer to the PHP Chinese website!