选择utf8字符集并utf8_general_ci
整理。
显然,字段的排序规则(您想要存储印地语文本)应该是utf8_general_ci
.
要更改表字段,请运行
ALTER TABLE `<table_name>` CHANGE `<field_name>` `<field_name>` VARCHAR(100)
CHARSET utf8 COLLATE utf8_general_ci DEFAULT '' NOT NULL;
连接到数据库后,首先运行以下语句
mysql_set_charset('utf8');
Eg:
//setting character set
mysql_set_charset('utf8');
//insert Hindi text
mysql_query("INSERT INTO ....");
检索数据
//setting character set
mysql_set_charset('utf8');
//select Hindi text
mysql_query("SELECT * FROM ....");
在浏览器上打印任何 unicode 文本(例如印地语文本)之前,您应该通过添加元标记来设置该页面的内容类型
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Eg:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example Unicode</title>
</head>
<body>
<?php echo $hindiText; ?>
</body>
</html>
Update:
mysql_query("SET CHARACTER SET utf8") has changed to
mysql_set_charset('utf8');
这是更改字符集的首选方法。不建议使用 mysql_query() 来设置它(例如 SET NAMES utf8)。看http://php.net/manual/en/function.mysql-set-charset.php*