且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何***地配置 PHP 以处理 UTF-8 网站

更新时间:2023-11-27 12:44:52

PHP 与 Unicode 内容的假设问题有些夸大其词.自 1998 年以来,我一直在做多语言网站,直到我在某处读到它时才知道可能会出现问题 - 多年后和网站.

The supposed issues of PHP with Unicode content have been somewhat overstated. I've been doing multilingual websites since 1998 and never knew there might be an issue until I've read about it somewhere - many years and websites later.

这对我来说很好用:

Apache 配置(在 httpd.conf 或 .htaccess 中)

Apache configuration (in httpd.conf or .htaccess)

AddDefaultCharset utf-8

PHP(在 php.ini 中)

PHP (in php.ini)

default_charset = "utf-8"
mbstring.internal_encoding=utf-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On
mbstring.func_overload=6 

MySQL

CREATE 使用 utf8_* 整理的数据库,让表继承数据库排序规则和使用 "SET NAMES utf8"

CREATE your database with an utf8_* collation, let the tables inherit the database collation and start every connection with "SET NAMES utf8"

HTML(在 HEAD 元素中)

HTML (in HEAD element)

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">