Recent Changes - Search:

PITS main list

edit sidebar

Main sidebar

PmWiki

pmwiki.org

00031

Summary: ucwords function does not work propely for some languages
Created: 2004-09-06 04:43
Status: Closed - fixed
Category: Bug
From: Zverik
Assigned:
Priority: 5
Version: 1.0.8
OS: WinXP/Apache/4.1

Description: It's written in the PHP Manual, in the discussion of ucwords function. On some languages, e.g. Russian, this function uppercases letters in the middle of words. Suggested fix:

 function ucwords_fix($string) {
   $temp = preg_split('/(\W)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE );
foreach ($temp as $key=>$word) {
$temp[$key] = ucfirst(strtolower($word));
}
return join ('', $temp);
}

This function is used once in pmwiki.php and once in search.php. I've changed it for my version, but it'll be erased after the next PmWiki upgrade.


Hmm. How about this instead?

  function ucwords_fix($string) {
    return preg_replace('/\\b(\\w)/e',"strtoupper('$1')",$string);
  }

This simply capitalizes any word character that is not preceded by another word character. Seems like this would be shorter+more efficient. --Pm


That code also works correctly, thanx. And looks better :) --Zverik


In v1, I changed pmwiki.php to use the preg_replace() above instead of ucwords(), and got rid of ucwords() from search.php (it's a case-insensitive search so it doesn't matter). Should appear in 1.0.9.

Also fixed this bug in v2. --PmPm

Edit - History - Print - Recent Changes - Search
Page last modified on September 10, 2011, at 11:56 AM