utf 8 - str_replace doesn't work with array arguments on PHP -
the following code doesn't work on php. actual result: 'ЯЯЯ' -> 'ЯЯЯ' (should 'яяя') why?
function strtolower_rus($string) { $upper = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я',' '); $lower = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я',' '); return strtolower(str_replace($upper, $lower, $string)); }
updated:
i use utf encoding on source file. can't use cp-1251 encoding because apache doesn't accept it. what's solution?
updated:
also have checked following code:
$lower = array('Я' => 'я'); function strtolower_rus($string) { return strtolower(strtr($string, $lower)); }
it returns ugly char instead 'я':(
check code below. works fine.
header('content-type: text/html; charset=utf-8'); function strtolower_rus($string) { $upper = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я',' '); $lower = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я',' '); return str_replace($upper, $lower, $string); }
$result = strtolower_rus('БНaktaraz bhatta');
echo $result;
Comments
Post a Comment