编程语言
首页 > 编程语言> > php转为xml

php转为xml

作者:互联网


 必须安装 PhpOffice 扩展库  才能跑
use PhpOffice\PhpWord\Shared\XMLWriter;
 public function toXml($data, $eIsArray=FALSE) {
  $this->xml = new XmlWriter();
   $this->version = '1.0';
	 $this->encoding = 'UTF-8';
  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);
  }
 }

标签:xml,encoding,value,eIsArray,PhpOffice,key,php,转为
来源: https://blog.csdn.net/apanpan8126/article/details/121227250