PHP Array2xml class implementation arrays into XML instances, array2xmlxml_php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.