Home > Backend Development > PHP Tutorial > The Array2xml class in PHP converts arrays into XML instances, array2xmlxml_PHP tutorial

The Array2xml class in PHP converts arrays into XML instances, array2xmlxml_PHP tutorial

WBOY
Release: 2016-07-13 10:12:12
Original
823 people have browsed it

The Array2xml class in php implements the conversion of arrays into XML instances, array2xmlxml

The example in this article describes the method of converting arrays into XML using the Array2xml class in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

Copy code The code is as follows:

class Array2xml
{
var $xml;
Function array2xml($array,$encoding='utf-8') {
           $this->xml='';
          $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 spaces and only take the text before the spaces as key
                   list($key,)=explode(' ',$key);
                                                                              $xml.="<$key>";
$xml.=is_array($val)?$this->_array2xml($val):$val;
//Remove the spaces and only take the text before the spaces as key
               list($key,)=explode(' ',$key);
                $xml.="";
}
         return $xml;
}
}

I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/923900.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/923900.htmlTechArticleThe Array2xml class in php implements the conversion of arrays into XML method. Share it with everyone for your reference. Specific implementation...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template