php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54315 Some string functions doesn't work as expected with cyrillic characters
Submitted: 2011-03-19 12:16 UTC Modified: 2011-03-19 13:49 UTC
From: sms at inbox dot ru Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.6 OS: Windows 7
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sms at inbox dot ru
New email:
PHP Version: OS:

 

 [2011-03-19 12:16 UTC] sms at inbox dot ru
Description:
------------
At least two string functions fail with cyrillic characters (cp1251) as of version 5.3.6:
strtolower() and strtoupper().

Test script:
---------------
setlocale(LC_ALL, 'ru_RU');
echo 'strtoupper: '.strtoupper('test тест').'<br>strtolower: '.strtolower('TEST ТЕСТ');

Expected result:
----------------
strtoupper: TEST ТЕСТ
strtolower: test тест

Actual result:
--------------
strtoupper: TEST тест
strtolower: test ТЕСТ

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-19 12:40 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2011-03-19 12:40 UTC] pajoye@php.net
Please see the note about Windows and Locale strings at 
http://www.php.net/setlocale

For a portable and reliable locale support, I would suggest to move to intl, 
http://www.php.net/intl
 [2011-03-19 12:58 UTC] sms at inbox dot ru
I had to go back to 5.3.5 where these functions work as expected.
5.3.6 breaks existing and working scripts
 [2011-03-19 13:04 UTC] pajoye@php.net
-Status: Bogus +Status: Feedback
 [2011-03-19 13:04 UTC] pajoye@php.net
ru_RU would not work reliably before (or now) as it is not a recognized locale. 
See the links on the setlocale documentation page for a list of the available 
locale (and cp).

However, the only change in 5.3.6 is that the Locale related APIs are not per 
thread instead of per process. Making them thread safe and avoid many possible 
crashes.

Which web server and SAPI do you use? Can you try this code using CLI (cmd line) 
too?
 [2011-03-19 13:33 UTC] sms at inbox dot ru
-Status: Feedback +Status: Open
 [2011-03-19 13:33 UTC] sms at inbox dot ru
In 5.3.5 these functions work as expected even without setlocale().
I tried setlocale() after this problem was found.

I use Apache 2.2.17 (downloaded @ http://www.apachelounge.com/download/) and php as a module (php5apache2_2.dll)

Just checked CLI - functions work fine
 [2011-03-19 13:39 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2011-03-19 13:39 UTC] pajoye@php.net
ok, that confirms what I was suspecting.

What happens is that setlocale is now actually working. As in really set the 
Locale, per thread, instead of per process (most likely on request or server initializations).

It most likely worked because your system local is set correctly.

Please try using the correct Locale ID (see the msdn link to get the right one 
for Russia).
 [2011-03-19 13:46 UTC] sms at inbox dot ru
-Status: Feedback +Status: Open
 [2011-03-19 13:46 UTC] sms at inbox dot ru
setlocale(LC_ALL, 'russian') solved the problem.
Thanks!
 [2011-03-19 13:49 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2011-03-19 13:49 UTC] pajoye@php.net
Back to not a bug status :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 11:01:30 2024 UTC