简体   繁体   English

如何将php设置为utf-8

[英]How to set php to utf-8

I am having problems with my code setting the utf-8 我的代码设置utf-8时遇到问题

I have set 我已经设定

header('Content-Type: text/html; charset=utf-8');

I also tried 我也试过

ini_set('default_charset','utf-8');

I have not tried 我没有尝试

$mysqli->set_charset("utf8")

as I am not even connecting to the sql database. 因为我什至没有连接到sql数据库。 I have five files 我有五个档案

core.php l18n.php l18n_js.php lang.php and response_class.php core.php l18n.php l18n_js.php lang.phpresponse_class.php

Core calls l18n.php and response_class.php 核心呼叫l18n.phpresponse_class.php

Then we have lang.php which is a dummy webpage with the meta charset already set to utf-8 and it calls to l18n_js.php and it has core.php included with it which then returns the correct language file. 然后,我们有了lang.php,这是一个虚拟网页,其元字符集已设置为utf-8,并调用l18n_js.php ,并且包含core.php ,然后返回正确的语言文件。

I am telling you what is going on as to ask do I need to set the header on each of the php files, as well as ini_set I am having so much difficulty making sure it is encoded to utf-8 and not show characters like ó él te h all messed up 我告诉你这是怎么回事,问我是否需要在每个php文件上设置标题,以及ini_set我很难确保将其编码为utf-8并且不显示ó él te hó él te h都搞砸了

Please see this previous answer for how to configure PHP to handle UTF-8. 请参阅前面的答案,以了解如何配置PHP以处理UTF-8。 If it still doesn't work, anywhere that you expect UTF-8 output from your database, use 如果仍然无法正常工作,请在希望从数据库输出UTF-8的任何地方使用

htmlentities($foobar, ENT_QUOTES, 'UTF-8');

The last parameter is optional if you are running PHP >= 5.4.0, but I always include it for backwards compatibility. 如果您正在运行PHP> = 5.4.0,则最后一个参数是可选的,但是为了向后兼容,我始终将其包括在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM