note 91145 added to function.preg-split
| From: | chrisATcmbuckleyDOTcoDOTuk at osu1 dot php dot net | Date: | Wed, 27 May 2009 12:08:58 +0000 |
| Subject: | note 91145 added to function.preg-split | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156057@lists.php.net to get a copy of this message | ||
The previous function failed to take into account the possibility that the first letter was
lower-case. Here's a fix (also adding $glue parameter):
<?php
function spacify($camel, $glue = ' ') {
return $camel[0] . substr(implode($glue, array_map('implode',
array_chunk(preg_split('/([A-Z])/',
ucfirst($camel), -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE), 2))), 1);
}
echo spacify('CamelCaseWords'); // 'Camel Case Words'
echo spacify('camelCaseWords'); // 'camel Case Words'
?>
----
Server IP: 87.124.35.190
Probable Submitter: 193.36.79.206
----
Manual Page -- http://www.php.net/manual/en/function.preg-split.php
Edit -- https://master.php.net/note/edit/91145
Del: integrated -- https://master.php.net/note/delete/91145/integrated
Del: useless -- https://master.php.net/note/delete/91145/useless
Del: bad code -- https://master.php.net/note/delete/91145/bad+code
Del: spam -- https://master.php.net/note/delete/91145/spam
Del: non-english -- https://master.php.net/note/delete/91145/non-english
Del: in docs -- https://master.php.net/note/delete/91145/in+docs
Del: other reasons-- https://master.php.net/note/delete/91145
Reject -- https://master.php.net/note/reject/91145
Search -- https://master.php.net/manage/user-notes.php