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 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面