-
-
Save khusseini/e77ea8831f713650f433 to your computer and use it in GitHub Desktop.
camelize + underscore in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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