note 108325 added to function.ucwords
| From: | jaffogmonkeytailgmaildecimalcom | Date: | Tue, 17 Apr 2012 12:00:01 +0000 |
| Subject: | note 108325 added to function.ucwords | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187206@lists.php.net to get a copy of this message | ||
Another function to make all words start with a capital letter, based on word boundary (\b). This
is, at least in my humble opinion, a lot cleaner and simpler.
(Note: it is advised to use a recent version of PHP when implementing this function, since the word
boundary (\b) may give weird results when processing strings with Unicode characters. Also see this
comment: www.php.net/manual/en/regexp.reference.escape.php#102868 )
<?php
function ucwordsAll($s)
{
return preg_replace('~\b(\w+)\b~e', 'ucfirst("\\1")', $s);
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 82.148.204.224
----
Manual Page -- http://www.php.net/manual/en/function.ucwords.php
Edit -- https://master.php.net/note/edit/108325
Del: integrated -- https://master.php.net/note/delete/108325/integrated
Del: useless -- https://master.php.net/note/delete/108325/useless
Del: bad code -- https://master.php.net/note/delete/108325/bad+code
Del: spam -- https://master.php.net/note/delete/108325/spam
Del: non-english -- https://master.php.net/note/delete/108325/non-english
Del: in docs -- https://master.php.net/note/delete/108325/in+docs
Del: other reasons-- https://master.php.net/note/delete/108325
Reject -- https://master.php.net/note/reject/108325
Search -- https://master.php.net/manage/user-notes.php