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?
Related Topics
HTML Form: Redirection depending on Radiobutton or Checkbox State
Tutorial | 0 Comments
PHP: Current Date and Time
Tutorial | 0 Comments
Create URL for Website from Title of Page
Tutorial | 0 Comments
PHP: Sending an E-Mail
Tutorial | 0 Comments
PHP Mail Function: UTF-8 E-Mail Headers
Info | 0 Comments
Send Form Input as an Array to PHP Script
Tip | 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.
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:
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