note 82592 added to function.strtoupper

From: Date: Thu, 17 Apr 2008 16:59:56 +0000
Subject: note 82592 added to function.strtoupper
Groups: php.notes 
Request: Send a blank email to php-notes+get-138413@lists.php.net to get a copy of this message
It has been mentioned in a previous comment that all you need to do to let PHP's strtoupper() do the conversion - instead of writing more or less complicated functions yourself - is to specify the locale in which you're doing the case conversion: <?php setlocale(LC_CTYPE, "de_AT") ?> It is important to note that setlocale() will silently fail if it can't find the specified locale on your system, so *always* check its return value. Try different spellings: using "de_AT" as an example, there are various combinations that may or may not work for you: "de", "de_AT.utf8", "de_AT.iso-8859-1", "de_AT.latin1", "de_AT@euro", etc). If you can't find an appropriate locale setting, check your system configuration (locales are a system-wide setting, PHP gets them from the OS). On Windows, locales can be set from the Control Panel; on Linux it depends on your distribution. You can try "sudo dpkg-reconfigure locales" on Debian-based distros, or configure them manually. On Ubuntu Dapper, I had to copy entries over from /usr/share/i18n/SUPPORTED to /var/lib/locales/supported.d/local, then do the dpkg-reconfigure. After you're done, restart the web server. That said, there are special cases where you want to do the conversion manually. In German, for example, the letter 'ß' (szlig) only exists as a lower-case character, and so doesn't get converted by strtoupper. The convential way to express a 'ß' in an uppercase string is "SS". This function will take care of this exception (for Latin1 and most of Latin9, at least): <?php define("LATIN1_UC_CHARS", "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ"); define("LATIN1_LC_CHARS", "àáâãäåæçèéêëìíîïðñòóôõöøùúûüý"); function uc_latin1 ($str) { $str = strtoupper(strtr($str, LATIN1_LC_CHARS, LATIN1_UC_CHARS)); return strtr($str, array("ß" => "SS")); } ?> ---- Server IP: 216.92.131.65 Probable Submitter: 213.129.239.202 ---- Manual Page -- http://www.php.net/manual/en/function.strtoupper.php Edit -- https://master.php.net/note/edit/82592 Del: integrated -- https://master.php.net/note/delete/82592/integrated Del: useless -- https://master.php.net/note/delete/82592/useless Del: bad code -- https://master.php.net/note/delete/82592/bad+code Del: spam -- https://master.php.net/note/delete/82592/spam Del: non-english -- https://master.php.net/note/delete/82592/non-english Del: in docs -- https://master.php.net/note/delete/82592/in+docs Del: other reasons-- https://master.php.net/note/delete/82592 Reject -- https://master.php.net/note/reject/82592 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#138413) next »