note 91142 modified in function.preg-split by danbrown

From: Date: Wed, 27 May 2009 13:47:43 +0000
Subject: note 91142 modified in function.preg-split by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156060@lists.php.net to get a copy of this message
Here's a helpful function to space out your CamelCase using preg_split: <?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' ?> --was-- Here's a helpful function to space out your CamelCase using preg_split: <?php function spacify($camel) { return implode(' ', array_map('implode', array_chunk(preg_split('/([A-Z])/', $camel, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE), 2))); } echo spacify('CamelCaseWords'); // 'Camel Case Words' ?> http://php.net/manual/en/function.preg-split.php

« previous php.notes (#156060) next »