当我输入此代码并从数据库中调用它时,它会将文本显示为问号或字母,它们是阿拉伯字母,所以 UTF8 应该可以工作,但我不知道现在不会。
<?php
header("Content-Type: application/json; charset=UTF-8");
$server = "";
$username = "";
$password = "";
$database = "";
$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);
$sql = "SELECT * FROM events WHERE id='1' ";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());
$records = array();
while($row = mysql_fetch_assoc($result)) {
$records[] = $row;
}
mysql_close($con);
print_r($records);
?>
它显示为结果
Array
(
[0] => Array
(
[id] => 1
[event] => ????? ?????
[speaker] => ???? ???????
[area] => ???????
[place] => ???? ??????
[addr] => ??? ???? ????????
[datefrom] => 2012-10-05
[dateto] =>
[timefrom] => 19:26:27
[timeto] =>
)
)