PHP代码
- <?php
- //公共声明
- header('Content-type: text/json');
- html_entity_decode($string, ENT_QUOTES, 'UTF-8');
- //回调参数设置
- $param="Jsoncallback";
- $callback=$_REQUEST[$param];
- $students=array(
- array("风清扬","1101","23","52819911"),
- array("许志飞","1101","23","52819911"),
- array("令狐冲","1102","21","52819901"),
- array("任我行","1103","22","52819991"),
- array("任盈盈","1104","24","52819981"),
- array("东方不败","1105","26","52819981")
- );
- $tempBegin='<style>*{margin:0;padding:0;}h1{font-size:16px;text-align:center; line-height:45px;}body{color:#333;font-size:14px;font-family:"MicrosoftYahei";background:#B7CACC;}div{border:1px solid #405E7B; border-bottom:0; width:95%; margin:0 auto;background:#fff;content:"";display:table;clear:both}li{line-height:35px;list-style:none;width:25%;text-align:center;border-bottom:1px solid #405E7B;float:left;}</style><h1>最近风云人员名单</h1><div>';
- foreach($students as $v){
- $tempBegin.='
- <ul>
- <li>'.$v[0].'</li>
- <li>'.$v[1].'</li>
- <li>'.$v[2].'</li>
- <li>'.$v[3].'</li>
- </ul>
- ';
- }
- $tempEnd=$tempBegin.'</div>';
- //echo $tempEnd;
- $str1=base64_encode($tempEnd);
- $str2='{"dataList":"'.$str1.'"}';
- $jsonStr=$callback."(".$str2.")";
- //判断请求参数存在就会输出Json数据
- //if(isset($callback)&&!empty($callback)){
- if(isset($callback)){
- echo $jsonStr;
- }
- //判断请求参数不存在就输出错误信息
- if(!isset($callback)){
- header("Content-type: text/html; charset=utf-8");
- $str="<h1>400 Required String parameter '{$param}' is not present</h1><hr /><small>http Request with error params: none callback function</small>";
- echo $str;
- }
- ?>