让Apache正确处理不同编码的文件避免中文乱码

打印 上一主题 下一主题

主题 939|帖子 939|积分 2821

安装了apache2.4.39以后,默认编码是UTF-8,不管你文件是什么编码,齐备按这个来剖析,因此 GB2312编码文件内的中文将显示为乱码。
  1. <!doctype html>
  2. <html>
  3. <head>
  4.         <meta http-equiv="Content-Type" content="text/html;charset=GB2312">
  5.         <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6.         <meta name="renderer" content="webkit">
  7.         <meta name="force-rendering" content="webkit">
  8.         <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />       
  9.         <meta http-equiv="Content-Language" content="zh-cn">
  10.     </head>
  11.     <body>       
  12.         <span>中文测试</span> <hr/>
  13. <?php
  14.     header('Content-type:text/html;charset=GB2312');
  15.     // $input_filed = '<input type="text" name="username" value="'.$_POST['username'].'">';
  16.     // echo $input_filed;
  17.     $input_name = '<input type = "text" name = username value = "'.$_POST['username'].'">';
  18.     echo '请输入姓名:' . $input_name;
  19.     echo '<hr/>';
  20.         echo "中文测试";
  21.     // //Example #1 $_POST 范例
  22.     // echo 'Hello ' . htmlspecialchars($_POST["name"]) . '!';
  23. ?>
  24. </body>
  25. </html>
复制代码

办理方案:
打开apache配置文件 \Apachexxx\conf\httpd.conf ,查找AddDefaultCharset,查看设置的是啥,改为
AddDefaultCharset off
假如配置文件中没有AddDefaultCharset的话就加上一句
AddDefaultCharset off

改完了记得重启Apache

如许,Apache就能按照文件中设定的编码来正确剖析文件了,前提是你的文件存储格式必须与设定编码同等。


假如不设置 AddDefaultCharset ,那么新安装完Apache后,默认都是用 UTF-8 编码来剖析页面的。



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

东湖之滨

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表