您的位置:首页 > 编程语言 > PHP开发

php从数据库生成数组,输出中文json,不使用urlencode

2013-11-02 01:23 706 查看
先将php 编码设为utf8:

header("Content-type: text/html; charset=utf-8");


从数据库取数据

$conn=mysql_connect("localhost","root","") or die("connot connect");
mysql_query("set names utf8");
mysql_select_db("database");

$sql="select * from table";

$re=mysql_query($sql,$conn);


将数据压入数组:

$arr=array();

while($row=mysql_fetch_array($re,MYSQL_ASSOC))
{
array_push($arr,$row);
}


编码输出json格式数据:

echo json_encode($arr,JSON_UNESCAPED_UNICODE);


注:适合PHP5.4以上.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: