[nycphp-talk] ucfirst question
Michael B Allen
mba2000 at ioplex.com
Tue Jun 12 20:30:14 EDT 2007
On Tue, 12 Jun 2007 19:59:55 -0400
David Krings <ramons at gmx.net> wrote:
> Hi!
>
> Being a ucfirst issue, I want to capitalize the first letter in a
> string. What caught my attention is this sentence in the PHP
> documentation: "Note that 'alphabetic' is determined by the current
> locale. For instance, in the default "C" locale characters such as
> umlaut-a (ä) will not be converted."
>
> Well, that is what potentially might happen. Is there a less language
> discriminatory version of ucfirst or do I need to snip off the first
> character and check it against ä,ö, and ü to make them Ä, Ö, and Ü? That
> will take care of German, but what about other languages?
>
> The locale of my system is US-English, but the script could run on other
> locales as well. Is there any way to switch the locale on the fly? Even
> if, I'd neet to noodle the string through ucfirst through all quite a
> bunch of locales.
By default programs (and thus PHP scripts) run in the C locale. If you
call setlocale(LC_CTYPE, ""); this will switch to the locale specified
in the environment usually throught the LANG variable. So you can test
this by running your script like:
$ LANG=de_DE.UTF-8 ./myscript.php
> This is "bupid" how my 2 year old would put it.
Much of PHP is derived from the the C language standards. Because C is a
machine language abstraction, it is deliberately coarse about things that
different systems may or may not support (e.g. i18n). This is contrary to
the top-down method of designing more modern and user friendly scripting
languages but it provides somewhat of a guarantee that there will be
no holes in the API since C is the common denominator of programming
languages.
Mike
--
Michael B Allen
PHP Active Directory Kerberos SSO
http://www.ioplex.com/
More information about the talk
mailing list