Skip to content

Instantly share code, notes, and snippets.

@Cezarion
Forked from troelskn/underscore.php
Created December 17, 2013 12:27
Show Gist options
  • Save Cezarion/8004157 to your computer and use it in GitHub Desktop.
Save Cezarion/8004157 to your computer and use it in GitHub Desktop.
<?php
/**
* Transforms an under_scored_string to a camelCasedOne
*/
function camelize($scored) {
return lcfirst(
implode(
'',
array_map(
'ucfirst',
array_map(
'strtolower',
explode(
'_', $scored)))));
}
/**
* Transforms a camelCasedString to an under_scored_one
*/
function underscore($cameled) {
return implode(
'_',
array_map(
'strtolower',
preg_split('/([A-Z]{1}[^A-Z]*)/', $cameled, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment