This time to bring you to the PHP implementation of parsing XML for an array of case details, the PHP implementation of parsing XML for the attention of the array of considerations, the following is the actual case, together to see.
Recently want to do a plug-in mechanism, need to use XML, when parsing XML need to convert to an array, deliberately record one such parsing method
Xmldemo.xml file:
<?xml version= "1.0" encoding= "UTF-8"? ><main xmlns= "http://www.xiaoetongo.cn" versioncode= "1.0" >< Controller co= "Aritles" ><meth title= "test plug-in" do= "Aritle"/></controller><controller co= "Ari" > <meth title= "Test plug-in" do= "ar"/><meth title= "test plug-in" do= "a"/></controller><install><! [cdata[]]></install><upgrade><! [cdata[]]></upgrade></main>
PHP Code:
<?php$xmls=file_get_contents ("Xmldemo.xml"); $xml =simplexml_load_string ($xmls); $xmljson = Json_encode ($xml); $ Xml=json_decode ($xmljson, True); Var_dump ($xml);
Operation Result:
Array (4) {["@attributes"]=> Array (1) { ["Versioncode"]=> string (3) "1.0"} ["Controller"]=> Array (2) { [0]=> Array (2) { ["@attributes"]=> Array (1) { ["Co"]=> string (7) "Aritles" } ["Meth"]=> Array (1) { ["@attributes"]=> Array (2) { ["title"]=> string (12) "Test plug-in " [" Do "]=> string (6)" Aritle "}} } [1]=> Array (2) { [" @attributes "]=> Array (1) { [" Co "]=> string (3)" Ari " } [" Meth "]=> Array (2) { [0]= > Array (1) { ["@attributes"]=> Array (2) { ["title"]=> string (12) "Test plug-in" [" Do "]=> string (2)" Ar " } } [1]=> Array (1) { [" @attributes "]=> Array (2 { ["title"]=> string (12) "Test plug-in" ["Do"]=> string (1) "A" }}}} [" Install "]=> Array (0) {} [" Upgrade "]=> Array (0) {}}
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP calculates an integer set of extra-large numbers
PHP uses Curl to clone IP and refer steps