1、数据库:
CREATE DATABASE db_nameCHARACTER SET utf8DEFAULT CHARACTER SET utf8COLLATE utf8_general_ciDEFAULT COLLATE utf8_general_ci;
或者如果已经创建数据库:
ALTER DATABASE db_nameCHARACTER SET utf8DEFAULT CHARACTER SET utf8COLLATE utf8_general_ciDEFAULT COLLATE utf8_general_ci;CREATE TABLE table_name(...)DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
或者如果已经创建了表格:
ALTER TABLE tbl_nameDEFAULT CHARACTER SET utf8COLLATE utf8_general_ci;2、在php.ini中启用这一行:
extension=php_mbstring.dll
然后在相同的文件中配置以下内容:
mbstring.language = Neutralmbstring.internal_encoding = UTF-8mbstring.encoding_translation = Onmbstring.http_input = autombstring.http_output = UTF-8mbstring.detect_order = autombstring.substitute_character = nonedefault_charset = UTF-83、利用下列php函数替代:
mail() -> mb_send_mail()strlen() -> mb_strlen() strpos() -> mb_strpos()strrpos() -> mb_strrpos()substr() -> mb_substr()strtolower() -> mb_strtolower()strtoupper() -> mb_strtoupper()substr_count() -> mb_substr_count()ereg() -> mb_ereg()eregi() -> mb_eregi()ereg_replace() -> mb_ereg_replace()eregi_replace() -> mb_eregi_replace() split() -> mb_split()htmlentities($var) -> htmlentities($var, ENT_QUOTES, 'UTF-8')4、利用header和meta标签:
header('Content-type: text/html; charset=UTF-8') ;<meta http-equiv=\公众Content-type\公众 value=\"大众text/html; charset=UTF-8\"大众 />5、在数据库中的任何插入/更新之前,您该当实行以下操作:
mysql_query(\公众SET NAMES 'utf8'\公众);