This article mainly introduces the PHP XML and arrays to each other to translate the relevant information, the need for friends can refer to the following
PHP XML and Arrays convert each other
Array to XML function Arraytoxml ($arr) { $xml = "<xml>"; foreach ($arr as $key = + $val) { if (is_numeric ($val)) { $xml. = "<". $key. " > ". $val." </". $key." > "; } else{ $xml. = "<". $key. " ><! [cdata[]. $val. "] ></". $key." > "; } } $xml. = "</xml>"; return $xml; } Convert XML to array function Xmltoarray ($xml) { //disallow referencing of external XML entity Libxml_disable_entity_loader (true); $values = Json_decode (Json_encode (simplexml_load_string ($xml, ' simplexmlelement ', Libxml_nocdata)), true); return $values; }
Five pre-defined entities in the XML file:
< |
< |
Less than sign |
> |
> |
Greater than sign |
& |
& |
And |
' |
' |
Single quotation marks |
" |
" |
Double quotes |
The above is the whole content of this article, I hope that everyone's study has helped.