为什么我不能用header xml格式啊 可以查看源代码 但是页面不显示
<?php
header("content-type:text/html;charset=utf-8");
class Response{
/**
*按json方式输出通信数据
*@param integer $code状态码
*@param string $message 提示信息
*@param array $data 返回数据
*return string
**/
public static function json($code,$message='',$data=array()){
if(!is_numeric($code)){
return '';
}
$result = array(
'code'=>$code,
'message'=>$message,
'data'=>$data,
);
echo json_encode($result);
exit;
}
/**
*按xml方式输出通信数据
*@param integer $code状态码
*@param string $message 提示信息
*@param array $data 返回数据
*return string
**/
public static function xmlEncode($code,$message,$data = array()){
if(!is_numeric($code)){
return '';
}
$result = array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);
$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 = "";
$attr = "";
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'=>'帅哥',
'type'=>array(2,3,5)
);
Response::xmlEncode(200,'success',$data);
?>
报错如下
This page contains the following errors:
error on line 1 at column 19: String not closed expecting " or '
Below is a rendering of the page up to the first error.