Convert simplexml objects into Arrays

Source: Internet
Author: User
I shared the code for the first time. Today I used simplexml to parse xml files and searched for a lot of methods to directly convert object array objects into arrays. I found that many codes are not useful and many use recursion, share my code without $ xmlsimplexml_load_file (Publicsyn. xml); * The output here is the object (SimpleXMLEle

I shared the code for the first time. Today I used simplexml to parse xml files and searched for a lot of methods to directly convert object array objects into arrays. I found that many codes are not useful and many use recursion, share my code without $ xml = simplexml_load_file ('Public/syn. xml ');/* the output here is the object (SimpleXMLEle

I shared the code for the first time. Today I used simplexml to parse the xml file and searched for a lot of methods to directly convert the object array object into an array. I found that many codes are not easy to use.
Many of them use recursion to share my code. <无>
$ Xml = simplexml_load_file ('Public/syn. xml ');/* the output here is object (SimpleXMLElement) #20 (1) {["server"] => array (2) {[0] => object (SimpleXMLElement) #26 (2) {["server_name"] => array (2) {[0] => string (3) "777" [1] => string (6) "123456"} ["server_ip"] => string (13) "xxx. xxx. xxx. xxx "} [1] => object (SimpleXMLElement) #27 (2) {[" server_name "] => array (2) {[0] => string (3) "888" [1] => string (6) "123456"} ["server_ip"] => string (13) "xxx. xxx. xxx. xxx "}}*/$ json_xml = json_encode ($ xml); $ dejson_xml = json_decode ($ json_xml, true);/* the output here is array (1) {["server"] => array (2) {[0] => array (2) {["server_name"] => array (2) {[0] => string (3) "777" [1] => string (6) "123456"} ["server_ip"] => string (13) "xxx. xxx. xxx. xxx "} [1] => array (2) {[" server_name "] => array (2) {[0] => string (3) "888" [1] => string (6) "123456"} ["server_ip"] => string (13) "xxx. xxx. xxx. xxx "}}}*/

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.