Last active
August 29, 2015 14:01
-
-
Save ricardoriogo/5b4fcd3c4b65ef0cae2c to your computer and use it in GitHub Desktop.
Camelize and Decamelize
This file contains 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 | |
function decamelize($word) { | |
$word = preg_replace_callback ( | |
'/([A-Z])/', | |
function($matches){ | |
return strtolower('_' . $matches[0]); | |
}, | |
$word | |
); | |
return trim($word, '_'); | |
} | |
function camelize($word) { | |
return preg_replace_callback ( | |
'/(_)([a-z])/', | |
function($matches){ | |
return strtoupper($matches[2]); | |
}, | |
$word | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment