开发者

jQuery Autocomplete Turkish special character problems

I have problems with Turkish special characters my encoding system is ISO-8859-9 charset in headers and server.

//Database connections
include_once("ogr_con.php");
require_once("oraunit.php");

function strtoupper_tr($string){
  $upper=array("ü" => "Ü", "ö" => "Ö", "ğ" => "Ğ", "ş" => "Ş", "ç" => "Ç", "i" => "İ", "ı" => "I");
  return strtoupper(strtr($string,$upper));
}

function strtolower_tr($string){
  $low=array("Ü" => "ü", "Ö" => "ö", "Ğ" => "开发者_运维知识库ğ", "Ş" => "ş", "Ç" => "ç", "İ" => "i", "I" => "ı");
  return strtolower(strtr($string,$low));
}

$adi= strtolower_tr($_GET["q"]);
$adi[0]=strtoupper($adi[0]);
$soyadi= strtoupper_tr($_GET["q"]);
if (!$adi) return;

$adiquery="SELECT K.ADI||' '||K.SOYADI AS FLNAME 
           FROM personel.kisi k 
           WHERE K.ADI LIKE '%".$adi."%' OR K.SOYADI LIKE '%".$soyadi."%')";
$aq=oraArray($con, $adiquery, array());
if(is_array($aq)){
    while(list($sno,$u)=each($aq)){
        $uadi = $u['FLNAME'];
        echo "$uadi\n";
    }
}
  1. Functions strtoupper_tr and strtolower_tr not working for special characters.
  2. $uadi - when this values is returned not displayed properly in textbox.

    <script type="text/javascript">

    $(document).ready(function() {

    $("#fuadsoyad").autocomplete("get_name.php", {

    width: 260,

    matchContains: true,

    selectFirst: false

    });

    });

    </script>

Can anyone help me solve this problem?

What do you advice me to do?


A general advice when dealing with special characters : use the UTF-8 charset : it should support all characters your application will require, no matter what language you need.

And it'll facilitate things when working with Ajax, as the standard charset for Ajax is UTF-8.


I solved the problem. Let me explain how in case anyone might face it in the future. Select all needed data and put it in one variable as shown below as $hocalist

$adiquery="SELECT K.ADI||' '||K.SOYADI AS FLNAME 
           FROM personel.kisi k 
           WHERE K.ADI LIKE '%".$adi."%' OR K.SOYADI LIKE '%".$soyadi."%')";

$aq=oraArray($con, $adiquery, array());
$hocalist = "";
foreach($aq as $row) {
$hocalist .= ($hocalist != "" ? "," : "")."{label:'".addslashes($row[FLNAME])."',ID:'$row[KNO]'}";
}

After that pass this variable as an array to JS as shown below.

<script type="text/javascript">
$(document).ready(function() {
var hocalistesi = new Array(<?= $hocalist; ?>);
$("#fuadsoyad").autocomplete(hocalistesi, {
minChars: 0,
max: 50,
width: 460,
autoFill: false,
matchContains: true,
formatItem: function(row, i, max) {
 return row.label;
},
formatMatch: function(row, i, max) {
 return row.label;
},
formatResult: function (row) {
 return row.label;
}
});
});
</script> 

Of course if we talk about efficiency it is not that efficient but working with different character sets it might be accepted as solution. Hope will be helpful


You need to save the .js file itself as "Unicode", for example in Notepad:
Save As --> Encoding drop down --> Unicode


See the following blog, It proposes a keyboard extension. The full list of combinations is:

  • for the letter 'ğ', use 'Alt Gr' +'g';
  • for the letter 'ş', use 'Alt Gr' + 's';
  • for the letter 'ç', use 'Alt Gr' + 'c';
  • for the letter 'ü', use 'Alt Gr' + 'u';
  • for the letter 'ö', use 'Alt Gr' + 'o';
  • for the letter 'ı', use 'Alt Gr' + 'i'.


try iconv("windows-1254","UTF-8",$text);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜