Skip to content

Instantly share code, notes, and snippets.

@caseysoftware
Last active December 18, 2015 15:39
Show Gist options
  • Select an option

  • Save caseysoftware/5806196 to your computer and use it in GitHub Desktop.

Select an option

Save caseysoftware/5806196 to your computer and use it in GitHub Desktop.
preg_replace after, removing /e
public static function decamelize($word)
{
$callback = create_function('$matches',
'return strtolower(strlen("$matches[1]") ?
"$matches[1]_$matches[2]" : "$matches[2]");');
return preg_replace_callback(
'/(^|[a-z])([A-Z])/',
$callback,
$word
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment