我有以下php代码:
<?php
mysql_connect("localhost","root","*****");
mysql_select_db("MyData");
$sql=mysql_query("select * from menu");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>我的数据库是用utf8_unicode_ci编码的。因此,当我在浏览器中读取输出时,拉丁字符a显示得很好,而希腊字符显示为“?”.When我从数据库中读取的数据会定期显示。有没有人能告诉我怎么处理我的php代码?
发布于 2011-05-27 23:22:56
将这两个查询添加到mysql_select_db("MyData");之后:
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");发布于 2011-05-27 23:22:24
试一试
header('Content-type: text/plain;charset=UTF-8');您需要在脚本中的print()调用之前执行此操作。
发布于 2016-04-07 01:58:19
PHP:
header('Content-Type: text/html; charset=utf-8');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");HTML:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>文件:使用记事本将文件转换为UTF-8
https://stackoverflow.com/questions/6154301
复制相似问题