这是什么问题?
This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
2015-04-20
public static function xmlEncode($code,$message = '',$data = array()){
if (!is_numeric($code)) {
return '';
}
$result = array(
'code' => $code,
'message' => $message,
'data' => $data,
);
header("Content-Type:text/xml");
$xml = "<?xml version='1.0' encoding='UTF-8'?>\n";
$xml .="<root>\n";
$xml .=self::xmlToEncode($result);
$xml .="</root>";
echo $xml;
}
public static function xmlToEncode($data){
$xml ="";
foreach ($data as $key => $value) {
if (is_numeric($key)) {
$attr = "id='{$key}'";
$key = "item";
}
$xml .="<{$key}{$attr}>";
$xml .=is_array($value) ? self::xmlToEncode($value) : $value;
$xml .="</{$key}>\n";
}
return $xml;
}
}
$data = array(
'id' => '1',
'name' => 'wufei',
'type' => array(4,5,6),
'test' =>array(1,45,12=>array(155,'ttt')),
);
Response::xmlEncode(200,'数据传输成功',$data);
举报