无法显示阿拉伯语内容


Unable to display arabic content

我正在尝试从mysql数据库排序规则中获取阿拉伯语数据utf8_general_ci但是在数据库中插入数据工作正常。当我尝试获取数据时,它给了我一些不同的符号。

//*$response = array(); 
$username = "root";
$password = "";
$hostname = "localhost"; 
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("tellmedb",$dbhandle) 
 or die("Could not select tellmedb");

//execute the SQL query and return records
mysql_query("SET NAMES utf8");
mysql_query("set characer set utf8");
$result = mysql_query("SELECT * FROM tbl_restaurantara") or die(mysql_error()); 

// Check whether there is data(record more than 0) 
if (mysql_num_rows($result) > 0) 
{ 
 // looping result mysql_query 
 $response["list_rs"] = array(); 
 while ($row = mysql_fetch_array($result)) 
 { 
 // temp user array 
 $list_rs = array(); 
 $list_rs["id_rs"] = $row["id"]; 
 $list_rs["name_rs"] = stripslashes($row["name"]); 
 $list_rs["link_image_rs"] = 
 stripslashes($row["link_image"]);
 $list_rs["url1_rs"] = 
 stripslashes($row["url1"]);
 $list_rs["url2_rs"] = 
 stripslashes($row["url2"]);
 $list_rs["url3_rs"] = 
 stripslashes($row["url3"]); 
 $list_rs["address_rs"] = 
 stripslashes($row["address"]); 
 $list_rs["telepon_rs"] = 
 stripslashes($row["phone"]); 
 $list_rs["booking_rs"] = 
 stripslashes($row["bookingurl"]);
 $list_rs["offer_rs"] = 
 stripslashes($row["offersurl"]);
 $list_rs["location_rs"] = 
 stripslashes($row["location"]);
// display the query results in the form of an array
  array_push($response["list_rs"], $list_rs); 
 } 
 // success 
 $response["success"] = 1; 
 // echoing JSON response 
 echo json_encode($response,JSON_UNESCAPED_UNICODE); 
 } 
 else { 
 // No data 
 $response["success"] = 0; 
 $response["message"] = "No DATA"; 
 // echoing JSON response 
 echo json_encode($response,JSON_UNESCAPED_UNICODE); 
} 
//close the connection
mysql_close($dbhandle); */

输出如下:

/*وعب، أسباير زوÙ*/

首先,请确认阿拉伯语文本是否正确保存在数据库中,如果可以,则在从代码中删除此行后尝试

mysql_query("set characer set utf8");

并添加

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

此代码

如果阿拉伯语文本未正确保存在数据库中,请将数据库排序规则更改为 UTF-8。

试试这个:

// connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");
mysql_set_charset('utf8', $dbhandle);

同时删除此行:

mysql_query("set characer set utf8");

请参阅此处的讨论