Skip to content

Instantly share code, notes, and snippets.

@benhuang1024
Last active January 19, 2019 14:45
Show Gist options
  • Save benhuang1024/8ee5fa2bfcb0112692f662d10016de2e to your computer and use it in GitHub Desktop.
Save benhuang1024/8ee5fa2bfcb0112692f662d10016de2e to your computer and use it in GitHub Desktop.
字符串蛇形驼峰互转
<?php
function camelize($uncamelized_words,$separator='_')
{
$uncamelized_words = $separator. str_replace($separator, " ", strtolower($uncamelized_words));
return ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator );
}
function uncamelize($camelCaps,$separator='_')
{
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment