我尝试使用 Ajax 从 PHP 发出阿拉伯文本,但它显示正方形。来自http://www.w3schools.com/ajax/ajax_aspphp.asp的示例:
主页
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<script>
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","autoAJAX.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<h3>Start typing a name in the input field below:</h3>
<form action="">
First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions:<br> <span id="txtHint"></span></p>
</body>
</html>
仅用于文件 ( gethint.php
) 时使用阿拉伯语之类的
$a[]="المغرب";
$a[]="عمان";
$a[]="مصر";
$a[]="العراق";
$a[]="ليبيا";
当我们运行页面时,它会显示像��这样的正方形
我怎么解决这个问题?
示例 if (gethint.php) 从 oracle 数据库获取
<html>
<head>
<title></title>
</head>
<body>
<?php
//get the q parameter from URL
$q=$_REQUEST["q"];
include("connect.php");
$sqlSerchStaff = "select * from STAFF_INFO where STAFF_ID = :ID_v";
$stSerchStaff = oci_parse($con, $sqlSerchStaff);
oci_bind_by_name($stSerchStaff,':ID_v', $q);
if (!@oci_execute($stSerchStaff, OCI_DEFAULT)) {
$e = oci_error($stSerchStaff); // For oci_execute errors pass the statement handle
print htmlentities($e['message']);
print"<br> الرجاء التأكد من الرقم الوظيفي";
}
else
{
while($row = oci_fetch_array($stSerchStaff))
{
$VID1 = $row['STAFF_NAME_AR'];
}
$rowNo = oci_num_rows($stSerchStaff);
if ($rowNo == 0||$rowNo = null)
{
$response ="الرقم الوظيفي غير مدرج في القائمة";
//$response ="no suggestion";
//$response ="no Data";
}
else
{
//$rowNo = oci_num_rows($stSerchStaff);
$response = $VID1;
}
echo $response;
}
?>
</body>
</html>
如果我将gethint.php
php 保存在UTF-8
编码中,它将在print"<br> الرجاء التأكد من الرقم الوظيفي";
and中显示阿拉伯语$response ="الرقم الوظيفي غير مدرج في القائمة";
,但如果它来自数据库,则不会
我试着用这个//$response=iconv("UTF-8","windows-1250",$response);
but it not working
我使用 oracle 10g 我的数据库NLS_CHARACTERSET
是AR8MSWIN1256
并且NLS_NCHAR_CHARACTERSET
是AL16UTF16