note 64838 added to function.ucwords
| From: | egingell at sisna dot com | Date: | Fri, 21 Apr 2006 14:52:39 +0000 |
| Subject: | note 64838 added to function.ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108933@lists.php.net to get a copy of this message | ||
A smarter ucwords(). If the "word" begins with a special character, smart_ucwords() will
capitalize the second character.
<?
function smart_ucwords($str) {
$str = trim(strtolower($str));
// First get all the words
$words = explode(' ', $str);
while (list(, $word) = each($words)) {
if (preg_match("#[\/\\\\!@\\#$%^&*()_+=-><;:'\\"{}\\]\\[?\\.]#",
$word{0}, $matches)) {
$sub = substr($word, 1);
} else {
$sub = $word;
}
if (strlen($word) == 1) {
$sub = $word;
}
$new_words[] = ($matches && strlen($word) != 1 ? $matches[0] : '') .
ucfirst($sub);
}
$str = ucfirst(implode(' ', $new_words));
return $str;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 65.100.194.45
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.ucwords.php
Edit -- http://master.php.net/note/edit/64838
Del: integrated -- http://master.php.net/note/delete/64838/integrated
Del: useless -- http://master.php.net/note/delete/64838/useless
Del: bad code -- http://master.php.net/note/delete/64838/bad+code
Del: spam -- http://master.php.net/note/delete/64838/spam
Del: non-english -- http://master.php.net/note/delete/64838/non-english
Del: in docs -- http://master.php.net/note/delete/64838/in+docs
Del: other reasons-- http://master.php.net/note/delete/64838
Reject -- http://master.php.net/note/reject/64838
Search -- http://master.php.net/manage/user-notes.php