error on line 2 at column 1: Extra content at the end of the document

<?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);


?>

哪里出错啦 ??

小沈程
浏览 2170回答 1
1回答

rubyc

没有加根标签呀!XML文件只能有一个根标签!
打开App,查看更多内容
随时随地看视频慕课网APP