AJAX+PHP中的阿拉伯语


Arabic in AJAX+PHP

我试图使用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> الرجاء التأكد من الرقم الوظيفي";$response ="الرقم الوظيفي غير مدرج في القائمة";中显示阿拉伯语,但如果它来自数据库,它将不会

我试着用这个//$response=iconv("UTF-8","windows-1250",$response); but it not working

我正在使用oracle 10g我的数据库NLS_CHARACTERSETAR8MSWIN1256

而CCD_ 9是CCD_

您在HTML中写道,您的字符都是拉丁文:

<content="text/html; charset=windows-1252">

我认为你不想这么做,因为你使用的字符不在那个字符集中。

尝试使用:

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

您还提到您使用的是Oracle数据库,因此您可能需要检查该数据库和该表的排序规则。有关更多信息,请参阅Oracle文档。从本质上讲,您需要确保Oracle知道您正在将非拉丁字符放入表中。

如果您在创建表时设置CHARSET,这将比以后转换字符集容易得多。