duanjie3267 2009-11-22 14: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 14: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部