#14655 [Com]: ucwords failing randomly with international characters

From: Date: Tue, 27 Aug 2002 11:50:26 +0000
Subject: #14655 [Com]: ucwords failing randomly with international characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-17929@lists.php.net to get a copy of this message
ID: 14655 Comment by: fille@fukt.bth.se Reported By: xtango@netcombbs.com.ar Status: Assigned Bug Type: Strings related Operating System: Windows XP Pro (spanish) PHP Version: 4.1.0 Assigned To: hholzgra New Comment: I had this bug to. To get around it, I added some 'hair' to the code. $string=ucwords($string); //Bugfix from here on for($i=0;$i<strlen($string);$i++) if((ctype_upper($string[$i]) &&( $string[$i-1]==" " || $i==0 ))!=TRUE) $string[$i]=strtolower($string[$i]); I'm a PHP newbie so I guess some of you can come up with a brighter solution. This code lowercases _all_ letters that is not either the first in the string or following a space. If your application does not meet both this criterias, you might not want this code. Previous Comments: ------------------------------------------------------------------------ [2002-07-13 18:10:13] derick@php.net chancing status ------------------------------------------------------------------------ [2002-06-17 07:02:15] hholzgra@php.net setlocale() doesn't work well with multithreaded servers as the current locale is set globaly for all threads ------------------------------------------------------------------------ [2002-04-21 06:24:41] bs_php@infeer.com Confirming your bug (PHP 4.1.2 on W2k) setlocale() on windows is the problem! See bug #16718 http://bugs.php.net/bug.php?id=16718 ------------------------------------------------------------------------ [2002-01-22 08:03:40] martin@humany.com Some additional comments: I cant reproduce this in Linux (meaning the returned data doesnt change), but with PHP 4.1.1 in Window XP the problem exists, but only when i change locale, my default locale is: LC_COLLATE=C;LC_CTYPE=English_United States.1252;LC_MONETARY=C;LC_NUMERIC=C;LC_TIME=C and the output here is: ÑÁéÍóúàèìòùäëÏöÜ With linux: Ñáéíóúàèìòùäëïöü But if i change locale with: setlocale(LC_ALL, "english"); (Locale: English_United States.1252) The returned data differs at each function call ------------------------------------------------------------------------ [2001-12-23 15:51:45] venaas@php.net To me this sounds like a system problem. PHP only uses the systems notion of upper and space. When the character following the international character it is probably because the international character is treated as a space by the system (isspace() returning true). It's quite weird that the results are not consistent. The PHP function itself is quite straightforward, so I suspect the locale is not the same every time, or that the systems isspace() and possibly toupper() is broken. I can't say for sure though. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/14655 -- Edit this bug report at http://bugs.php.net/?id=14655&edit=1

« previous php.bugs (#17929) next »