tags:

views:

242

answers:

8

i have some text in foreign language in my page, but when i make it lowercase, it starts to look like this...


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

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

+4  A: 

have your tried using mb_strtolower()?

steelbytes
yes, i've test it. doesn't work.
Syom
@Syom did you specify UTF-8 as the encoding?
Pekka
might also need mb_internal_encoding() first
steelbytes
+1  A: 

Use mb_strtolower instead, as strtolower doesn't work on multi-byte characters.

R. Bemrose
`strtolower` does actually work on multibyte characters, it just works off of the current locale, which is not usually what you want in these cases.
Nick Bastin
A: 

Have you tried

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

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

The examples on that page appear to work.

You could also try:

$str = mb_strtolower($str, mb_detect_encoding($str));
Kevin
+1  A: 

strtolower() will perform the conversion in the currently selected locale only.

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

Pekka
A: 

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

mb_internal_encoding('UTF-8');

...

$b = mb_strtolower($a);
echo $b;
reko_t
A: 

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

intuited
A: 

thanks all. i must use

$a = "Երկիր Ավելացնել"
echo $b = mb_strtolower($a,"utf8");
//returns Երկիր Ավելացնել
Syom
+1  A: 

Php by default does not know about utf-8. It assumes any string is ASCII, so it strtolower converts bytes containing codes of uppercase letters A-Z to codes of lowercase a-z. As the UTF-8 non-ascii letters are written with two or more bytes, the strtolower converts each byte separately, and if the byte happens to contain code equal to letters A-Z, it is converted. In the result the sequence is broken, and it no longer represents 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. I any case, you need to spend some time to configure the mbstring settings to match your requirements.

SWilk