drol55885602 2013-07-27 09:20
浏览 19
已采纳

西里尔语显示为??? ???? 在PHP中[重复]

This question already has an answer here:

I'm trying to print values from the database, containing countrylist. One of the fields in this database is cyrilic. My PHP script looks like this:

include_once("db.php");

$query = mysql_query ("SELECT * FROM country");
$row = mysql_fetch_array($query);

do {
    $id = strtolower($row["id"]);
    $value = ($row["runame"]);
    echo $id . " " . $value . '<br/>';
} while ($row = mysql_fetch_array ($query));

The output from this script looks like this:

ad ???????
ae ???????????? ???????? ???????
af ??????????
ag ??????? ? ???????
ai ????????

So, apparently I need to set UTF-8 for this PHP script... somehow... Does anyone know how to do this? Thank you for your time!

</div>
  • 写回答

1条回答 默认 最新

  • duanliu8998 2013-07-27 09:32
    关注

    Try using SET NAMES utf8 after connecting to MySQL:

    mysql_query("SET NAMES utf8");
    

    Or if you are using cp1251 in the database, set this encoding.

    As the manual says:

    SET NAMES indicates what character set the client will use to send SQL statements to the server... It also specifies the character set that the server should use for sending results back to the client.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog