当前场景:discuz创建的网站,在里面放进制作的页面发现无论用utf-8,gb2312,gbk等都无法正常显示文字。各种乱码乱七八糟
使用工具putty(可以打开服务器就行)
- Apache服务器:在
httpd.conf
或apache2.conf
配置文件中(/etc/httpd/conf/httpd.conf)搜索AddDefaultCharset
指令,可以找到并设置默认编码。 - Nginx服务器:在
nginx.conf
配置文件中搜索charset
指令,可以设置默认编码。
看到是gb2312:
打开FileZilla把服务器文件下载到本地,打开Visual Studio Code把刚才下载的文件打开:
右下角一般会出现UTF-8,它表示着当前文件是什么类型编码,点击它会出现两个选项,选择:通过编码保存
例:httpd.conf查到是gb2312,文件编码类型选择gb2312保存
php代码填:
header('Content-Type: application/x-www-form-urlencoded; charset=gb2312');
html代码填:
<meta http-equiv="Content-Type" content="application/x-www-form-urlencoded; charset=gb2312">
把文件上传到服务器中,此时页面就成功的显示正常文字了。
------------------------------------------------------------------------------------------------------------
!!ai返回的回答仍然是乱码!!它回答默认UTF-8,把UTF-8转成GB2312
例:
$response = $sample->run($realQuestion);
echo $response;
改:
$response = $sample->run($realQuestion);
$gb2312String = mb_convert_encoding($response, 'GB2312', 'UTF-8');
header('Content-Type: application/x-www-form-urlencoded; charset=GB2312');
echo $gb2312String;