用脚本在php代码中搜索波斯语字符

时间:2014-08-20 06:40:53

标签: php internet-explorer character-encoding

我想在数据库中搜索一个字符串,我的代码在Firefox和Chrome中正确执行但在IE中数据的值是问号(?)并且它无法正常工作。 我搜索波斯语字符串,用英语搜索正确。 我写的时候

echo $data;
在IE中,它为每个字符返回一个问号,例如我写了علي,它返回???

我的代码是:

<?php
    include ("include/dbconnect_user.php");
?>
<script>
function search(str)
{
        if (window.XMLHttpRequest){
            xmlhttp=new XMLHttpRequest();
        }else{
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("txtSearch").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","users.php?data="+str,true);
        xmlhttp.send(); 
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>
<div id='img' align='center'></div>

<?php                   
if(isset($data)){
    $alternate = "2"; 
    echo "<table id='maintable' class='sortcompletecallback-applyZebra'>";
    foreach($disp_cols as $col) {

        if(!in_array($col, array("home", "work", "mobile", "select", "edit", "homepage", "details"))) {
          echo "<th>".ucfmsg(strtoupper($col))."</th>";
        } elseif(in_array($col, array("home", "work", "mobile"))) {
          echo "<th>".ucfmsg("PHONE_".strtoupper($col))."</th>";
        }
    }
    $sql="select * from `addressbook` where ";
    $sql.= " `lastname`   LIKE '%$data%'
                OR `firstname`  LIKE '%$data%'
                OR `work` like '%$data%'
                OR `email`      LIKE '%$data%'
                OR `unit`     LIKE '%$data%'
                OR `post`      LIKE '%$data%' ";

        $sql=mysql_query($sql);
        while($query=mysql_fetch_array($sql)){
            $firstname=$query['firstname'];
            $lastname=$query['lastname'];
            $mail=$query['email'];
            $work=$query['work'];
            $post=$query['post'];
            $unit=$query['unit'];
            $color = ($alternate++ % 2) ? "odd" : "";
            echo "<tr class='".$color."' name='entry'>";
            echo    "
                    <td style='padding-right:5px;'>$lastname $firstname</td>
                    <td align='left' style='padding-right:5px;'>$mail</td>
                    <td align='left'  style='padding-left:5px;'>$work</td>
                    <td align='center'  style='padding-left:5px;'>$unit</td>
                    <td align='left'  style='padding-left:5px;'>$post</td></tr>";
        }
    echo    "</table>";         

}else{
 include ("include/header.inc_user.php");

echo    "<div id='search-az'>
    <div style='font-size: 13px;'> جستجو 
    <input type='text'  name='search' tabindex='0' onkeyup='search(this.value)' autofocus />
            </div>
            </div><br />
            <hr />";

}
?>

    <div id='txtSearch'><div id='newdivSearchID'>

    </div>
    </div>

1 个答案:

答案 0 :(得分:0)

尝试替换

 xmlhttp.open("GET","users.php?data="+str,true);

使用:

 xmlhttp.open("GET","users.php?data="+encodeURIComponent(str),true);