Skip to content

Instantly share code, notes, and snippets.

@scones
Created April 9, 2018 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scones/e09c30e696246fda14578bcf8ab4910a to your computer and use it in GitHub Desktop.
Save scones/e09c30e696246fda14578bcf8ab4910a to your computer and use it in GitHub Desktop.
function decamelize($input_string) {
return preg_replace_callback(
'#(^|[a-z])([A-Z])#',
function (array $matches) {
$result = '';
if (0 === strlen($matches[1]))
$result = $matches[2];
else
$result = "{$matches[1]}_{$matches[2]}";
$result = strtolower($result);
return $result;
},
$input_string
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment