The Array2xml class implements an array of PHP into an XML instance, Array2xmlxml
In this paper, we describe the method of Array2xml class in PHP to transform the array into XML. Share to everyone for your reference. The implementation method is as follows:
Copy the Code code as follows:
<?php
Class Array2xml
{
var $xml;
function Array2xml ($array, $encoding = ' utf-8 ') {
$this->xml= ' <?xml version= "1.0" encoding= "'. $encoding. '? > ';
$this->xml.= $this->_array2xml ($array);
}
function getXml () {
return $this->xml;
}
function _array2xml ($array)
{
$xml = ";
foreach ($array as $key = = $val) {
if (Is_numeric ($key)) {
$key = "Item id=\" $key \ "";
}else{
Remove the space, just take the space before the text is key
List ($key,) =explode (", $key);
}
$xml. = "< $key >";
$xml. =is_array ($val)? $this->_array2xml ($val): $val;
Remove the space, just take the space before the text is key
List ($key,) =explode (", $key);
$xml. = " ";
}
return $xml;
}
}
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/923900.html www.bkjia.com true http://www.bkjia.com/PHPjc/923900.html techarticle in PHP, the Array2xml class implements an array into an XML instance, Array2xmlxml This example describes the Array2xml class in PHP to transform the array into XML method. Share to everyone for your reference. Concrete implementation ...