请教一个问题。关于php和xml的 最近我要写一个树形结构,本来我是发送一个数组给前台的flex,可是前台说要是能给他发送xml格式的,他就很容易接收。请教怎么把php的数组变成xml。。数组里面的元素不确定,告诉我个大概的知识就成,我去查一查,现在无从下手啊。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); }} eclipse 可以配合xdebug远程调试么?! php做伪静态怎么做啊 js 左右键的问题 很感谢 用正则如何取得URL地址,谢谢 PDO exec update 求教:本人这段单选按钮复选按钮与数据库相关的删除的代码有什么问题呢? 初学者的一个怪问题 这次真的晕了,关于正则的 为什么有些书上说 ' 支持转义字符 咋么在PHP中定义变量? \x7f-\xff疑惑 mysql查询很耗时间的问题
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);
}
}