Created
February 28, 2010 17:57
-
-
Save piouPiouM/317702 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Reverse a CamelCase string. | |
* | |
* Examples: | |
* uncamel('lowerCamelCase') === 'lower_camel_case' | |
* uncamel('UpperCamelCase') === 'upper_camel_case' | |
* uncamel('ThisIsAString') === 'this_is_a_string' | |
* uncamel('notcamelcase') === 'notcamelcase' | |
* uncamel('lowerCamelCase', ' | ') === 'lower | camel | case' | |
* | |
* @author Mehdi Kabab <http://pioupioum.fr/> | |
* @copyright 2010 Mehdi Kabab | |
* @license http://www.opensource.org/licenses/mit-license.html MIT License | |
* @link http://pioupioum.fr/snippets/php-function-uncamel-supprimer-camel-case.html | |
* | |
* @param string $content The CamelCase string. | |
* @param string $separator The glue for the compound words. Defaults to '_'. | |
* @return string | |
*/ | |
function uncamel($content, $separator = '_') | |
{ | |
$content = preg_replace('#(?<=[a-zA-Z])([A-Z])(?=[a-zA-Z])#e', "'$separator' . strtolower('$1')", $content); | |
$content{0} = strtolower($content{0}); | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment