note 108325 deleted from function.ucwords by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 17:09:31 +0000 |
| Subject: | note 108325 deleted from function.ucwords by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187660@lists.php.net to get a copy of this message | ||
Note Submitter: jaffog monkey tail gmail decimal com
----
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);
}
?>