當前位置: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);
熱點內容