This article to the students to introduce two simple examples, PHP array to XML and XML conversion array, I hope this article will help you friends.
PHP Array to XML
The code is as follows |
Copy Code |
function Array2xml ($array, $xml = False) { if ($xml = = = False) { $xml = new SimpleXMLElement (" ); } foreach ($array as $key = = $value) { if (Is_array ($value)) { Array2xml ($value, $xml->addchild ($key)); }else{ $xml->addchild ($key, $value); } } return $xml->asxml (); }
Header (' Content-type:text/xml '); Print Array2xml ($array); |
PHP XML to array
The code is as follows |
Copy Code |
$s = << Basic 1 4 3 1 2 EOS;
$a = Json_decode (Json_encode ((array) simplexml_load_string ($s)), 1); Print_r ($a); |
http://www.bkjia.com/PHPjc/632670.html www.bkjia.com true http://www.bkjia.com/PHPjc/632670.html techarticle This article to the students to introduce two simple examples, PHP array to XML and XML conversion array, I hope this article will help you friends. PHP array to XML code to copy code as follows ...