strtoupper

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

strtoupper

Post by spacebiscuit »

Hi,

I'm using the strtoupper function to convert a string to upper case. The string in this case features a foreign language character:

ú

When I output the string this character remains lower case whilst those aorund it are upper case. If I manually post in the uppercase character it correctly displays an uppercase.

I am wonderiing if this has something to do with the charset in the HTML heading?

Rob.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: strtoupper

Post by cpetercarter »

No, it is to do with the locale set by the operating system of your computer.

Have a look at the php manual entry on strtoupper, particularly the user comments, several of which suggest workrounds for cases where you want to convert non-standard characters to upper case.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: strtoupper

Post by Weirdan »

It's likely all you need is mb_strtoupper()
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: strtoupper

Post by spacebiscuit »

Thanks for the rpely.

mb_strupper removed the charachter entirely!

Rob.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: strtoupper

Post by Apollo »

Did you supply the correct encoding to mb_strtoupper?

If you tell mb_strtoupper that your string is utf-8, but it's really windows-1252 ansi for example, it may remove foreign characters because they're simply invalid bytes when interpreting the string as utf-8.
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: strtoupper

Post by spacebiscuit »

Fantatic that did it! I had to set the encloding to Windows-1252.

Many thanks!

Rob.
Post Reply