note 90521 added to function.ucwords
| From: | GregS at osu1 dot php dot net | Date: | Sun, 26 Apr 2009 16:16:30 +0000 |
| Subject: | note 90521 added to function.ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153784@lists.php.net to get a copy of this message | ||
I did the same thing as Catalin, but for French names.
Here's what I'm doing :
For each word (not considering the single-quote as a word boundary character) :
- Put the word in lower case
- If the word is "de", return, else, put the first letter in upper-case
- See if the second character of the word is a single-quote
- Yes ? Put the next char in upper case
- And if the char before the single quote is D, put it back to lower case (-> d)
This complies with the French rules for capitalization in names.
Sample results :
-d'Afoo Bar
-de Foo Bar
-O'Foo Bar
-Foo'bar
function my_ucwords($s) {
$s = preg_replace_callback("/(\b[\w|']+\b)/s", fixcase_callback, $s);
return $s;
}
function fixcase_callback($word) {
$word = $word[1];
$word = strtolower($word);
if($word == "de")
return $word;
$word = ucfirst($word);
if(substr($word,1,1) == "'") {
if(substr($word,0,1) == "D") {
$word = strtolower($word);
}
$next = substr($word,2,1);
$next = strtoupper($next);
$word = substr_replace($word, $next, 2, 1);
}
return $word;
}
----
Server IP: 89.31.146.176
Probable Submitter: 82.123.156.114
----
Manual Page -- http://www.php.net/manual/en/function.ucwords.php
Edit -- https://master.php.net/note/edit/90521
Del: integrated -- https://master.php.net/note/delete/90521/integrated
Del: useless -- https://master.php.net/note/delete/90521/useless
Del: bad code -- https://master.php.net/note/delete/90521/bad+code
Del: spam -- https://master.php.net/note/delete/90521/spam
Del: non-english -- https://master.php.net/note/delete/90521/non-english
Del: in docs -- https://master.php.net/note/delete/90521/in+docs
Del: other reasons-- https://master.php.net/note/delete/90521
Reject -- https://master.php.net/note/reject/90521
Search -- https://master.php.net/manage/user-notes.php