如何妥善处理国际字符的PHP / MySQL / Apache的 [英] How to properly handle international character in PHP / MySQL / Apache

查看:95
本文介绍了如何妥善处理国际字符的PHP / MySQL / Apache的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在PHP中创建一个应用程序可以处理在所有地方都统一code字 - 编辑字段,静态HTML,数据库。谁能告诉我,所有的参数/需要设置/用来实现这一目标的功能的完整列表?

I need to create an application in PHP that can handle all Unicode characters in all places — edit fields, static HTML, database. Can somebody tell me the complete list of all parameters / functions that need to be set / used to achieve this goal?

推荐答案

的Apache

服务器编码必须未设置或设置为UTF-8。这是通过apache的AddDefaultCharset指令完成。这可以去虚拟主机或一般的文件(见文档)。

The server encoding must be either not set, or set to UTF-8. This is done via the apache AddDefaultCharset directive. This can go to the virtualhost or the general file (see documentation).

AddDefaultCharset utf-8

的MySQL


  • 将数据库的排序规则为UTF-8

  • 设置连接编码。它可以作为一个具有mysqli_set_charset说来完成,或者通过连接只是后发送此:


    SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'

PHP

1,则应该设置页面为UTF-8字符集HTML,通过meta标签页上,或通过PHP头:

1- You should set the HTML charset of the page to be UTF-8, via a meta tag on the page, or via a PHP header:


    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-or-
    header('Content-type: text/html; charset=utf-8');

2 - 你应该总是使用MB *字符串相关的功能的版本,例如,mbstrlen而不是strlen的得到一个字符串的字符串长度。

2- You should always use the mb* version of string-related functions, for example, mbstrlen instead of strlen to get the string length of a string.

这应该让你有UTF-8无处不在,从页面的数据。测试你可以这样做:用firefox的页面,然后选择显示网页信息,任意位置单击右键。有效编码列在该页面。

This should allow you to have UTF-8 everywhere, from the pages to the data. A test you can do: right-click anywhere on the page using firefox, and select Show page information. The effective encoding is listed in that page.

这篇关于如何妥善处理国际字符的PHP / MySQL / Apache的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆