00 Votes

PHP: Umlauts and strtoupper

Question by Chematik | 2012-02-29 at 22:59

I have a string in PHP and would like to convert this string to uppercase letters. I use the following code for that:

$str = 'abc äöü';
echo strtoupper($str);
// output: ABC äöü

But now, there is a problem. I expect the output "ABC ÄÖÜ", but it gives me "ABC äöü". Apparently, strtoupper() is not working with the German umlauts and accented characters. What can I do?

ReplyPositiveNegative
00 Votes

Which letters strtoupper() actually converts to uppercase depends on the local setting. If you want to play it safe (usually, you can not change the local settings on your webspace anyway), you can use the following function:

$str = 'abc äöü';
echo mb_strtoupper($str,'UTF-8');
// output: ABC ÄÖÜ

With mb_strtoupper(), you can transform all Unicode characters as well as the umlauts to uppercase. As a parameter, you have to specify the string and the encoding, that is used. The encoding depends on the encoding that you are using on your site, usually that should be UTF-8.
2012-03-02 at 05:33

ReplyPositive Negative
Reply

Related Topics

PHP: Current Date and Time

Tutorial | 0 Comments

PHP: Sending an E-Mail

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.