Last active
April 25, 2016 12:29
-
-
Save linxlad/3b2859724738ba7f0bac378403cf62a4 to your computer and use it in GitHub Desktop.
Camel case to underscore
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
/** | |
* Return the underscored version of a CamelCase string. | |
* | |
* @return string | |
*/ | |
function camelCaseToUnderscore($camelCaseString) | |
{ | |
return ltrim( | |
strtolower( | |
preg_replace( | |
["/([A-Z]+)/", "/_([A-Z]+)([A-Z][a-z])/"], | |
["_$1", "_$1_$2"], | |
trim($camelCaseString) | |
) | |
), | |
'_' | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment