note 49304 deleted from function.ucwords by tularis
| From: | tularis@php.net | Date: | Sun, 23 Jan 2005 22:51:48 +0000 |
| Subject: | note 49304 deleted from function.ucwords by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83836@lists.php.net to get a copy of this message | ||
Note Submitter: arjini at gmail dot com
Reason: added to the manual
----
Not so much ucwords() related as it is capital letter related. I often use camel casing (as do
wikis), and I needed a reason to reverse the camel casing.
function unCamelCase($str){
$bits = preg_split('/([A-Z])/',$str,false,PREG_SPLIT_DELIM_CAPTURE);
$a = array();
array_shift($bits);
for($i = 0; $i < count($bits); ++$i)
if($i%2)
$a[] = $bits[$i - 1].$bits[$i];
return $a;
}
print_r(unCamelCase('MyFancyCamelCasedWord'));
Array
(
[0] => My
[1] => Fancy
[2] => Camel
[3] => Cased
[4] => Word
)