Problems with the strtolower function

I have a foreign language text on my page, but when I make it lowercase, it starts to look like this ...




$a = "Երկիր Ավելացնել"; echo $b = strtolower($a); //returns                 

I set <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> could you tell me why? thank you in advance

+22
php
Mar 25
source share
8 answers

try using mb_strtolower ()?

+45
Mar 25
source share

PHP5 is not compatible with UTF-8, so you still need to use the mb extension. I suggest you set the internal mb encoding to utf-8, and then you can freely use its functions without specifying all encodings:

 mb_internal_encoding('UTF-8'); ... $b = mb_strtolower($a); echo $b; 
+17
Mar 25
source share

I found this solution from here

 $string = 'Թ'; echo 'Uppercase: '.mb_convert_case($string, MB_CASE_UPPER, "UTF-8").''; echo 'Lowercase: '.mb_convert_case($string, MB_CASE_LOWER, "UTF-8").''; echo 'Original: '.$string.''; 

works for me (lowercase)

+8
Jul 26 '12 at 11:53 on
source share

You tried

http://www.php.net/manual/en/function.mb-strtolower.php

mb_strtolower () and specify the encoding as the second parameter?

The examples on this page work.

You can also try:

 $str = mb_strtolower($str, mb_detect_encoding($str)); 
+4
Mar 25 '10 at 14:48
source share

Php does not know about utf-8 by default. It assumes that any string is ASCII, so strtolower converts bytes containing capital letters AZ to lowercase codes az. Since non-ascii-UTF-8 letters are written with two or more bytes, strtolower converts each byte separately, and if the byte contains code equal to the letters AZ, it is converted. As a result, the sequence is interrupted and it no longer matches the correct character.

To change this, you need to configure the mbstring extension:

http://www.php.net/manual/en/book.mbstring.php

to replace strtolower with mb_strtolower or use mb_strtolower direclty. In any case, you need to spend some time to tune the mbstring options to suit your requirements.

+3
Mar 25 '10 at 14:53
source share

Use mb_strtolower since strtolower does not work with multibyte characters.

+2
Mar 25 '10 at 14:48
source share

strtolower () will only convert in the currently selected locale.

I would try mb_convert_case () . Make sure you explicitly specify the encoding.

+1
Mar 25
source share

You will need to set the locale; see the first example at http://ca3.php.net/manual/en/function.strtolower.php

0
Mar 25
source share



All Articles