Skip to content

Instantly share code, notes, and snippets.

@ricardoriogo
Last active August 29, 2015 14:01
Show Gist options
  • Save ricardoriogo/5b4fcd3c4b65ef0cae2c to your computer and use it in GitHub Desktop.
Save ricardoriogo/5b4fcd3c4b65ef0cae2c to your computer and use it in GitHub Desktop.
Camelize and Decamelize
<?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