Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting russian characters from upper case to lower case in php

I'm trying to change the case of russian characters from upper to lower.

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

This is the function I used and the output looks something like this

ЁЙ## ёѹ##`

Can anybody help me with this ? Thanks in advance

like image 243
Dhiraj Avatar asked Dec 16 '22 14:12

Dhiraj


2 Answers

$result = mb_strtolower($orig, 'UTF-8');

(assuming the data is in utf-8)

like image 109
zerkms Avatar answered Jan 30 '23 21:01

zerkms


Specify the charset within the HTML and use mb_strtolower() to convert case:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
    <head>
        <title></title>
    </head>
    <body>
<?
$string = 'ЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ' ;
echo mb_strtolower($string, 'UTF-8');
?>
    </body>
</html>

With the meta-tag it looks like this:

цукенгшщзхъфывапролджэячсмитьбю

Without the meta-tag it looks like this

цукенгшщзхъфывапролджÑÑчÑмитьбю
like image 39
Anne Avatar answered Jan 30 '23 22:01

Anne