[英]How to convert HTML code of Unicode to Real Unicode Character
Is there any php function that can convert 有没有可以转换的PHP函数
ابب
to it equallent unicode character 它等同于unicode字符
ت ب ا
I have googled a lot, But I think there is no any PHP built in function available for this purpose. 我已经google了很多,但我认为没有任何PHP内置功能可用于此目的。 Actually, I want to store the user submitted comments (that are in unicode characters) to mysql database.
实际上,我想将用户提交的注释(以unicode字符存储)存储到mysql数据库中。 But It is stored in this format
ابب
但它以这种格式存储
ابب
in mysql database. 在mysql数据库中。 I am also using
SET NAMES 'utf8'
in mysql query. 我也在mysql查询中使用
SET NAMES 'utf8'
。 The Output is in real unicode characters that is fine, but the insertion in mysql is in this format ابب
输出是真正的unicode字符,很好,但在mysql中的插入是这种格式
ابب
that i don't want. 我不想要的。 Any Solution??
任何解决方案
I googled It and found a very interesing solution here 我用谷歌搜索了它,并在这里发现了一个非常有趣的解决方案
I have also tried it and I think Its working 我也试过了,我认为它的工作原理
<?php
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
foreach($trans_tbl as $k => $v)
{
$ttr[$v] = utf8_encode($k);
}
$text = 'ابب';
$text = strtr($text, $ttr);
echo $text;
?>
for mysql solution you can set the character set as 对于mysql解决方案,您可以将字符集设置为
$mysqli = new mysqli($host, $user, $pass, $db);
if (!$mysqli->set_charset("utf8")) {
die("error");
}
if you 如果你
1 - set your html page's lang encoding to utf-8
which includes your forms 1 - 将您的html页面的lang编码设置为
utf-8
,其中包括您的表单
2 - only use your forms to enter input into your related MySQL db tables 2 - 仅使用表单在相关的MySQL数据库表中输入输入
3 - set all collations to utf8_unicode_ci
in your MySQL (tables and rows collations) 3 - 将所有排序
utf8_unicode_ci
设置为MySQL中的utf8_unicode_ci
(表和行排序规则)
4 - if you have premission you can also setyour MySQL DB collation as utf8_unicode_ci
4 - 如果你有预约,你也可以将MySQL DB校对作为
utf8_unicode_ci
then you won't see entities in your mySQL records also 那么你也不会在mySQL记录中看到实体
This is my solution I use and have no trouble with my mother language which also has lots of unicode characters. 这是我使用的解决方案,我的母语也有很多unicode字符。
Below I introduce you my db connection php code & recommend (by using prepared statements; please check http://php.net/manual/en/mysqli.quickstart.prepared-statements.php ) 下面我介绍我的数据库连接php代码和推荐(通过使用准备好的语句;请查看http://php.net/manual/en/mysqli.quickstart.prepared-statements.php )
//mysql bağlantısı
global $db_baglanti;
$db_baglanti = new mysqli(vt_host, vt_user, vt_password, vt_name);
if ($db_baglanti->connect_errno)
{
echo "MySQL bağlantısı kurulamadı: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (!$db_baglanti->set_charset("utf8"))
{
printf("utf8 karakter setinin yüklenmesinde problem oluştu: %s\n", $db_baglanti->error);
}
else
{
$db_baglanti->set_charset("utf8");
}
I think you should be able to use mysql_set_charset()
http://php.net/manual/en/function.mysql-set-charset.php to set the mysql connection encoding so when you retrieve these from the DB and display them they should be fine. 我认为你应该能够使用
mysql_set_charset()
http://php.net/manual/en/function.mysql-set-charset.php来设置mysql连接编码,这样当你从数据库中检索它们并显示它们时应该没事。
According to php.net "This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used." 根据php.net“从PHP 5.5.0开始,这个扩展已被弃用,将来会被删除。相反,应该使用MySQLi或PDO_MySQL扩展。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.