Skip to content

Instantly share code, notes, and snippets.

@khusseini
Forked from troelskn/underscore.php
Last active October 10, 2015 06:17
Show Gist options
  • Save khusseini/e77ea8831f713650f433 to your computer and use it in GitHub Desktop.
Save khusseini/e77ea8831f713650f433 to your computer and use it in GitHub Desktop.
camelize + underscore in php
<?php
/**
* Transforms an under_scored_string to a camelCasedOne
*/
function camelize($scored) {
return preg_replace('/[-_]([a-z])/e', 'strtoupper("$1")', $scored);
}
/**
* Transforms a camelCasedString to an under_scored_one
*/
function underscore($cameled) {
return preg_replace('/([a-z])([A-Z])/e', '"$1" . strtolower("_$2")', $cameled);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment