亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我不能用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.


正在回答

3 回答

我的也是這個問題 ? 必須得查看源代碼才可以看到 ?頁面直接瀏覽報錯

0 回復 有任何疑惑可以回復我~
#1

歌德猛男 提問者

非常感謝!
2016-11-03 回復 有任何疑惑可以回復我~

("content-type:text/html;charset=utf-8")??? test/html? charset 中間有個分號? 去掉就行了? 而且你是通過xml格式??? 所以要改成test/xml?

0 回復 有任何疑惑可以回復我~

你寫的header("content-type:text/html;charset=utf-8"); ? 中的content-type ? ?應該是Content-type或者Content-Type吧,是不是大小寫的問題

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
PHP開發APP接口
  • 參與學習       79159    人
  • 解答問題       608    個

APP通信接口技術,不得不掌握的法寶,學完之后你會受益良多

進入課程

為什么我不能用header xml格式啊 可以查看源代碼 但是頁面不顯示

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號