當前位置:ag真人国际官网-ag旗舰厅官方网站 » 編程語言 » 手機php代碼

手機php代碼-ag真人国际官网

發布時間: 2024-07-02 23:57:44

php 做安卓 伺服器 怎麼編寫代碼

php只能做服務端的數據處理,然後將數據用介面的方式,以json的數據形式給安卓客戶端程序調用。

test.php

$code,
'message'=>$message,
'data'=>$data,
);

if($type=='json'){
self::json($code,$message,$data);
exit;
}elseif($type=='array'){
var_mp($result);
}elseif($type=='xml'){
self::xmlencode($code,$message,$data);
exit;
}else{
//todo
}
}
/**
*按json方式輸出通信數據
*@paraminteger$code狀態碼
*@paramstring$message提示信息
*@paramarray$data數據
*returnstring
*/
publicstaticfunctionjson($code,$message='',$data=array()){

if(!is_numeric($code)){
return'';
}

$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data
);

echojson_encode($result);
exit;
}

/**
*按xml方式輸出通信數據
*@paraminteger$code狀態碼
*@paramstring$message提示信息
*@paramarray$data數據
*returnstring
*/
publicstaticfunctionxmlencode($code,$message,$data=array()){
if(!is_numeric($code)){
return'';
}

$result=array(
'code'=>$code,
'message'=>$message,
'data'=>$data,
);

header(content-type:text/xml);
$xml=
;
$xml.=
;

$xml.=self::xmltoencode($result);

$xml.=
;
echo$xml;
}

($data){

$xml=$attr=;
foreach($dataas$key=>$value){
if(is_numeric($key)){
$attr=id='{$key}';
$key=item;
}
$xml.=<{$key}{$attr}>;
$xml.=is_array($value)?self::xmltoencode($value):$value;
$xml.=
;
}
return$xml;
}

}
1,
'name'=>david
);
response::show(200,'success',$data);
熱點內容
resin下jsp不能正常編譯 發布:2024-07-17 16:34:44 瀏覽:229
sqlserver如何切換主備伺服器 發布:2024-07-17 16:23:02 瀏覽:299
mc18伺服器ip 發布:2024-07-17 16:23:02 瀏覽:379
仙境傳說手游腳本 發布:2024-07-17 16:09:24 瀏覽:691
matlab命令窗口和新建腳本 發布:2024-07-17 15:51:26 瀏覽:375
建ftp文件夾 發布:2024-07-17 15:51:26 瀏覽:955
魔獸撿物腳本 發布:2024-07-17 15:27:56 瀏覽:130
開發ip伺服器 發布:2024-07-17 15:24:42 瀏覽:388
安卓系統視頻製作哪個好用 發布:2024-07-17 15:10:47 瀏覽:210
androidapk結構 發布:2024-07-17 15:10:43 瀏覽:945
网站地图