<?php
/**
* 按xml方式输出通信方式
* @param integer $code状态码
* @param string $message提示信息
* @param array $data数据
* return string
*/
class response{
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'?>";
$xml .="<root>";
$xml .= self::xmlToEncode($result);
$xml .="</root>";
echo $xml;
}
public static function xmlToEncode($data){
$xml = "";
foreach($data as $key => $value){
$xml .= "<{$key}>";
$xml .= $value;
$xml .= "</{$key}>";
}
return $xml;
}
}
$data = array(
'id' => 1,
'name' => 'fengxupeng',
);
Response::xmlEncode(200,'success',$data);
?>
哪里出错啦 ??
rubyc