0

The following code doesn't work on PHP. The actual result: 'ЯЯЯ' -> 'ЯЯЯ' (should be 'яяя') Why?

function strtolower_rus($string) { 
    $upper = array('А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я',' ');
     $lower = array('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я',' ');
    return strtolower(str_replace($upper, $lower, $string));
} 

UPDATED:

I use UTF encoding on the source file. But can't use CP-1251 encoding because apache doesn't accept it. What's a solution?

UPDATED:

Also I have checked the following code:

$lower = array('Я' => 'я');

function strtolower_rus($string) { 
    return strtolower(strtr($string, $lower));
} 

It returns an ugly char instead 'я':(

4

1 回答 1

0

Check the code below. It 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;

于 2013-10-07T09:48:42.127 回答