From: jo at feuersee dot de
Operating system: Linux
PHP version: 5.2.3
PHP Bug Type: I18N and L10N related
Bug description: strtoupper() and locales: inconsistent behavior
Description:
------------
I stumbled about this issue while debugging a project which uses PEAR
XML_Parser which relys on the assumption that strtoupper() works for all
US-ASCII characters no matter which locale or encoding.
Unfortunately, it does not.
This has been discussed in PHP bugs
22003
21771
35583
The letter i isn't converted to I by strtoupper() when the locale is set
to turkish (via setlocale(LC_ALL, 'tr_TR'))
However, the letter i is converted to I by strtoupper() when the locale is
set to turkish (via setlocale(LC_ALL, 'tr'))
mb_strtoupper() does work under all encodings.
Now, despite blaming the Unicode guys or the turkish language or
whatever:
How are we supposed to code properly under these circumstances?
My proposal:
strtoupper/lower() claim to be locale aware, but they really aren't (try
to upperchase umlaut äöü under locale de_DE - doesn't work at all). Thus,
redefining these functions to work for 7-bit encoded (US-ASCII) data _only_
won't change anything. Skip the locale dependency, then the locale tr_TR
will work.
Reproduce code:
---------------
[EMAIL PROTECTED] ~> php -r 'setlocale(LC_ALL, "tr"); $text = "begin";
printf("%s
%s\n", strtoupper($text), bin2hex(strtoupper($text))); '
BEGIN 424547494e
[EMAIL PROTECTED] ~> php -r 'setlocale(LC_ALL, "tr_TR"); $text = "begin";
printf("%s
%s\n", strtoupper($text), bin2hex(strtoupper($text))); '
BEG�N 424547dd4e
[EMAIL PROTECTED] ~> php -r 'setlocale(LC_ALL, "tr_TR.UTF-8"); $text = "begin";
printf("%s %s\n", strtoupper($text), bin2hex(strtoupper($text))); '
BEGiN 424547694e
Expected result:
----------------
BEGIN 424547494e
(for all locales)
Actual result:
--------------
(see above)
--
Edit bug report at http://bugs.php.net/?id=42063&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=42063&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=42063&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=42063&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=42063&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=42063&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=42063&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=42063&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=42063&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=42063&r=support
Expected behavior: http://bugs.php.net/fix.php?id=42063&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=42063&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=42063&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=42063&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42063&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=42063&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=42063&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=42063&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=42063&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=42063&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=42063&r=mysqlcfg