duanjie3267 2009-11-22 22:17 采纳率: 0%
浏览 116
已采纳

将网站编码从ISO-8859-1切换到UTF-8

I am trying to convert my existing PHP webpage to use UTF-8 encoding.

To do so, I have done the following things:

  1. specified UTF-8 as the charset in the meta content tag at the start of my webpage.
  2. change the default_charset to UTF-8 in the php.ini.
  3. specified UTF-8 as the iconv encoding in the php.ini file.
  4. specified UTF-8 in my .htaccess file using: AddDefaultCharset UTF-8.

Yet after all that, when i echo mb_internal_encoding(), it shows as ISO-8859-1. What am I missing here? I know I could use auto_prepend to attach a script that changes the default encoding to UTF-8, but I'm just trying to understand what I'm missing.

Thanks

  • 写回答

2条回答 默认 最新

  • dongzhun6952 2009-11-22 22:37
    关注

    mb_internal_encoding() doesn't effect the output of your scripts per se, it effects the default encoding when using the multibyte string functions and the conversion of POST and GET inputs.

    Simply set with

    mbstring.internal_encoding='UTF-8'
    

    in your php.ini file, or programmatically with:

    mb_internal_encoding('UTF-8');
    

    Speaking of the mb_ functions, you'll need to rewrite your scripts to use these, e.g. mb_strlen() instead of strlen.(), etc.

    Also check what HTTP content-type headers are being outputted, though from what you've done it should be ok.

    If you using a database, you'll also have to convert that too, and specify that you're using UTF-8 when connecting to it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作