Firstly my this code is a dummy code, its written in sql just for understanding purpose. so kindly bear with it for now as i will change it to mysqli later on..
首先,我的这段代码是一个伪代码,它是用sql编写的,目的是为了理解。因此,请暂时接受它,因为稍后我将把它改为mysqli。
i have some arabic text that needs to get stored in database and then display it at user end.
我有一些阿拉伯文本需要存储在数据库中,然后在用户端显示。
To store it in database i changed the collation to utf8_general_ci and used the following code in connection file i.e config.php
为了将它存储在数据库中,我将排序规则更改为utf8_general_ci,并在连接文件i中使用了以下代码。e config。
<?php
$link = mysql_connect('abc','abc','abc') or die('Cannot connect to the DB');
mysql_select_db('abc',$link) or die('Cannot select the DB');
mysql_set_charset("UTF8", $link);
mysql_query("set character_set 'utf8'");
?>
with its help i was able to store the data in arabic form, but now in my php file, that is supposed to display data i am getting alpha numeric data ( something like this: u062du0631u0641u0629n). sample code of my php file is
在它的帮助下,我能够以阿拉伯语的形式存储数据,但是现在在我的php文件中,它应该显示数据,我得到的是alpha数值数据(如下图:u062du0631u0641u0629n)。我的php文件的示例代码是
<?php
require_once('config.php');
$vendorid = $_REQUEST['vendorid'];
$select = mysql_query("select * from vendor where id = '".$vendorid."'");
$posts = array();
if(mysql_num_rows($select)) {
while($post = mysql_fetch_assoc($select)) {
$posts[] = $post;
}
header('Content-type: application/json');
echo stripslashes(json_encode(array('vendor list'=>$posts)));
} else {
header('Content-type: application/json');
echo stripslashes(json_encode(array('vendor list'=>'No vendor available')));
}
?>
4 个解决方案
#1
1
yo can use this code to view utf8 character and string
您可以使用此代码查看utf8字符和字符串
mysql_set_charset('utf8',$link);
#2
1
try this before query execution:
在执行查询之前,请尝试以下操作:
mysql_query("SET character_set_results = 'utf8'");
mysql_query("character_set_client = 'utf8'");
mysql_query("character_set_connection = 'utf8'");
mysql_query("character_set_database = 'utf8'");
#3
0
- Use the mysqli_* API instead of mysql_*. The latter is deprecated.
- 使用mysqli_* API而不是mysql_*。后者是弃用。
- Change to $mysqli_obj->set_charset('utf8') instead of SET NAMES.
- 更改为$ sqmyli_obj ->set_charset('utf8'),而不是设置名称。
- I assume u062d is 'HAH'? Do you have no other way to type Arabic than to use the Unicode codes? In some contexts, Windows lets you do Alt+062D.
- 我猜u062d是“哈”吗?除了使用Unicode代码之外,您没有其他方式输入阿拉伯语吗?在某些上下文中,Windows允许使用Alt+062D。
- Generally, html pages with a suitable at the start allow entry of any utf8 character (including Arabic).
- 一般来说,具有合适开头的html页面允许输入任何utf8字符(包括阿拉伯语)。
- I don't think you need
stripslashes
in the context where you are using it. Or do you have extra slashes in the database? (That would be a problem.) - 我认为你不需要在你使用它的上下文中使用划线。或者你在数据库中有额外的斜杠吗?(这会是个问题。)
- I see nothing in your code that would have generated 'u062d'.
- 我在你的代码中没有看到任何会生成u062d的东西。
- Do SELECT HEX(col), col FROM ... to pick out a row that has one of those Unicode strings; that may give us more clues.
- 请从…中选择HEX(col), col。选择具有这些Unicode字符串之一的行;这可能会给我们更多的线索。
#4
0
brother try check
弟弟尝试检查
- http://www.ar-php.org/en_index-php-arabic.html
- http://www.ar-php.org/en_index-php-arabic.html
- Arabic text output php mysql utf-8 conversion issue
- 阿拉伯文本输出php mysql utf-8转换问题
- php page not displaying arabic text
- php页面不显示阿拉伯语文本
- http://www.ar-php.org/faq-php-arabic.html
- http://www.ar-php.org/faq-php-arabic.html
#1
1
yo can use this code to view utf8 character and string
您可以使用此代码查看utf8字符和字符串
mysql_set_charset('utf8',$link);
#2
1
try this before query execution:
在执行查询之前,请尝试以下操作:
mysql_query("SET character_set_results = 'utf8'");
mysql_query("character_set_client = 'utf8'");
mysql_query("character_set_connection = 'utf8'");
mysql_query("character_set_database = 'utf8'");
#3
0
- Use the mysqli_* API instead of mysql_*. The latter is deprecated.
- 使用mysqli_* API而不是mysql_*。后者是弃用。
- Change to $mysqli_obj->set_charset('utf8') instead of SET NAMES.
- 更改为$ sqmyli_obj ->set_charset('utf8'),而不是设置名称。
- I assume u062d is 'HAH'? Do you have no other way to type Arabic than to use the Unicode codes? In some contexts, Windows lets you do Alt+062D.
- 我猜u062d是“哈”吗?除了使用Unicode代码之外,您没有其他方式输入阿拉伯语吗?在某些上下文中,Windows允许使用Alt+062D。
- Generally, html pages with a suitable at the start allow entry of any utf8 character (including Arabic).
- 一般来说,具有合适开头的html页面允许输入任何utf8字符(包括阿拉伯语)。
- I don't think you need
stripslashes
in the context where you are using it. Or do you have extra slashes in the database? (That would be a problem.) - 我认为你不需要在你使用它的上下文中使用划线。或者你在数据库中有额外的斜杠吗?(这会是个问题。)
- I see nothing in your code that would have generated 'u062d'.
- 我在你的代码中没有看到任何会生成u062d的东西。
- Do SELECT HEX(col), col FROM ... to pick out a row that has one of those Unicode strings; that may give us more clues.
- 请从…中选择HEX(col), col。选择具有这些Unicode字符串之一的行;这可能会给我们更多的线索。
#4
0
brother try check
弟弟尝试检查
- http://www.ar-php.org/en_index-php-arabic.html
- http://www.ar-php.org/en_index-php-arabic.html
- Arabic text output php mysql utf-8 conversion issue
- 阿拉伯文本输出php mysql utf-8转换问题
- php page not displaying arabic text
- php页面不显示阿拉伯语文本
- http://www.ar-php.org/faq-php-arabic.html
- http://www.ar-php.org/faq-php-arabic.html