Home > php教程 > PHP源码 > body text

看不见的问题(个性的json)

PHP中文网
Release: 2016-05-25 16:58:26
Original
1163 people have browsed it

在服务端返回json数据时,文件保存成utf8,json解析不了。而把文件保存成utf8无BOM就可以解析。
就因为几个用肉眼看不到的字符  

case sentence_info:  // 每日一句列表
         
        $pageIndex=($_POST[pageIndex]-1)*$_POST[displayNumber];
        $displayNumber=$_POST[displayNumber];
        // $month=$_POST[month];
        $result_num = mysql_query("select sid from i_sentence");
        $total = mysql_num_rows($result_num);
        $total_page=ceil($total/$displayNumber);
        $arr=array();
        $query=mysql_query("select sid,picture,picture2,content,note,browsenum,translation,tts,
        dateline from i_sentence where 1=1 order by dateline desc limit $pageIndex,$displayNumber");
 
        while($row=mysql_fetch_assoc($query))
        {
             
            $row[note]=urlencode(preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$row[note]));
            $row[translation]=urlencode(preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$row[translation]));   
            // $row[imgs]=get_img($row[id]);
            $row[dateline]=urlencode(date('Y M d',strtotime($row[dateline])));
            $picinto=pathinfo($row[picture2]);  
            if(!empty($picinto[extension]))
            {
                $row[picture]=$row[picture2];
            }
            unset($row[picture2]); 
            $arr[]=$row;
        }
        $data=urldecode(json_encode($arr));
        $s=mysql_errno();
        //echo $data;
        echo "{\"s\":$s,\"data\":$data,\"total\":$total_page}";
         
    break;
Copy after login

 以上就是看不见的问题(个性的json)的内容,更多相关内容请关注PHP中文网(www.php.cn)!

                   

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template