最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php實(shí)現(xiàn)將數(shù)組轉(zhuǎn)換為XML的方法

 更新時(shí)間:2015年03月09日 12:11:07   作者:和諧  
這篇文章主要介紹了php實(shí)現(xiàn)將數(shù)組轉(zhuǎn)換為XML的方法,實(shí)例分析了php操作數(shù)組及XML格式文件的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)將數(shù)組轉(zhuǎn)換為XML的方法。分享給大家供大家參考。具體如下:

1. php代碼如下:

<?php
class A2Xml {
 private $version = '1.0';
 private $encoding = 'UTF-8';
 private $root  = 'root';
 private $xml  = null;
 function __construct() {
  $this->xml = new XmlWriter();
 }
 function toXml($data, $eIsArray=FALSE) {
  if(!$eIsArray) {
   $this->xml->openMemory();
   $this->xml->startDocument($this->version, $this->encoding);
   $this->xml->startElement($this->root);
  }
  foreach($data as $key => $value){
 
   if(is_array($value)){
    $this->xml->startElement($key);
    $this->toXml($value, TRUE);
    $this->xml->endElement();
    continue;
   }
   $this->xml->writeElement($key, $value);
  }
  if(!$eIsArray) {
   $this->xml->endElement();
   return $this->xml->outputMemory(true);
  }
 }
}
$res = array(
 'hello' => '11212',
 'world' => '232323',
 'array' => array(
  'test' => 'test',
  'b' => array('c'=>'c', 'd'=>'d')
 ),
 'a' => 'haha'
);
$xml = new A2Xml();
echo $xml->toXml($res);

2. 運(yùn)行效果如下圖所示:

PS:這里再為大家提供幾款關(guān)于xml操作的在線工具供大家參考使用:

在線XML/JSON互相轉(zhuǎn)換工具:
http://tools.jb51.net/code/xmljson

在線格式化XML/在線壓縮XML:
http://tools.jb51.net/code/xmlformat

XML在線壓縮/格式化工具:
http://tools.jb51.net/code/xml_format_compress

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

罗平县| 都昌县| 清新县| 阿拉尔市| 乐至县| 前郭尔| 万源市| 成武县| 镇坪县| 乡城县| 松滋市| 泌阳县| 永昌县| 晋中市| 玉龙| 德昌县| 绥阳县| 偃师市| 嵊州市| 昆明市| 呼玛县| 金寨县| 阳原县| 彭州市| 鄂托克前旗| 贺州市| 遂平县| 固安县| 同仁县| 德兴市| 河间市| 增城市| 南乐县| 鄂托克前旗| 策勒县| 荔浦县| 苗栗县| 鄂托克前旗| 志丹县| 九龙城区| 刚察县|