jquery and php utf-8 encode decode -



jquery and php utf-8 encode decode -

hi in project making turkish letter checkking script. if user enters key not turkish letter give warning .

this jquery code

$( "#singup_surname" ).keyup(function() { var singup_surname = $( "#singup_surname" ).val().trim(); var request = $.ajax({ url: "check.php", type: "post", encoding:"utf-8", data: { singup_surname_only:singup_surname}, datatype: "html" }); request.done(function( msg ) { msg=msg.trim(); if(msg=="ok"){ $('#singup_surname').removeclass('wrongfield'); $('#singup_surname').addclass('truefield'); }else if(msg=="no"){ $('#singup_surname').removeclass('truefield') $('#singup_surname').addclass('wrongfield') }else { alert("database connection error"); } }); });

for illustration if user enters "ş" letter post send this

singup_surname_only=%c5%9f

on php side code

$singup_surname_only=$_post['singup_surname_only']; if (isset($singup_surname_only)) { $singup_surname_only=urldecode($singup_surname_only); $tk = array('a','b','c','Ç','d','e','f','g','Ğ','h','i','İ','j','k','l','m','n','o','Ö','p','r','s','Ş','t','u','Ü','v','y','z','a', 'b', 'c','ç', 'd', 'e', 'f', 'g','ğ', 'h', 'i','ı', 'j', 'k', 'l', 'm', 'n', 'o','ö', 'p', 'r', 's','ş','t','u','ü', 'v','y','z' ) ; $tk=array("%c5%9f","ö"); $arr1 = str_split($singup_surname_only); $lettercount = count($arr1); $i=1; while ($i<=$lettercount) { if (in_array($arr1["$i"], $tk)) { }else echo 'no'; $i++; } }

what see on php side in array 'ş' letter becomes 'Å'

how solve problem give thanks much

that's how check if there turkish characters in string $str:

$tkreg = sprintf('~^[%s]*$~u', join('', $tk)); $thereareonlyturkishcharacters = preg_match($tkreg, $str) === 1; var_dump($thereareonlyturkishcharacters);

php jquery

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -