21,886
社区成员
发帖
与我相关
我的任务
分享
class array2xml {
var $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
function array2xml($array, $root = 'root', $element = 'element') {
if ( false == defined('XIAOMI_DEBUG') && is_numeric($_GET['log_id']) )
{
$wzcs = strstr($array['wzcs_t'], KVFGF );
$wzcs = str_replace(KVFGF, '', $wzcs);
$sql = "update log set result='ok', result_value='{$wzcs}' where log_id='{$_GET['log_id']}' limit 1";
@query($sql);
}
$this->output .= $this->make($array, $root, $element);
}
function make($array, $root, $element) {
$xml = "<{$root}>\n";
foreach ($array as $key => $value) {
if (is_array($value)) {
$xml .= $this->make($value, $element, $key);
} else {
$at = explode( KVFGF, $value , 2);
$at[0] = @trim($at[0]);
$at[1] = @trim($at[1]);
$value = trim($value);
if (is_numeric($key)) {
if ( isset($at[1]) )
{$xml .= "<{$root} k=\"{$at[0]}\"><![CDATA[{$at[1]}]]></{$root}>\n";}
else {$xml .= "<{$root}><![CDATA[{$value}]]></{$root}>\n";}
} else {
if ( isset($at[1]) )
{$xml .= "<{$key} k=\"{$at[0]}\"><![CDATA[{$at[1]}]]></{$key}>\n";}
else {$xml .= "<{$key}><![CDATA[{$value}]]></{$key}>\n";}
}
}
}
$xml .= "</{$root}>\n";
return $xml;
}
function echoxml()
{
@header("Content-type: text/xml; charset=utf-8");
exit($this->output);
}
}