Skip to content

Instantly share code, notes, and snippets.

@linxlad
Last active April 25, 2016 12:29
Show Gist options
  • Save linxlad/3b2859724738ba7f0bac378403cf62a4 to your computer and use it in GitHub Desktop.
Save linxlad/3b2859724738ba7f0bac378403cf62a4 to your computer and use it in GitHub Desktop.
Camel case to underscore
/**
* 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