tv/include/class/Xml.php
2025-11-28 14:28:58 +08:00

44 lines
1.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* File操作类
* Author易如意
* QQ51154393
* Urlwww.eruyi.cn
*/
class Array_to_Xml{
private $version = '1.0';
private $encoding = 'UTF-8';
private $root = 'eruyi';
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);
}
}
}
?>