PHP converts XML into an array. php xml array _ PHP Tutorial

Source: Internet
Author: User
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.


<?php$string = <<
   Forty What? 
     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...

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.