如
“ask-simple”转换为“askSimple”
“ask-simple-answer”转换为“askSimpleAnswer”
PHP中文网2017-04-10 14:59:44
function camelcase($str){
return preg_replace_callback('/([-_]+([a-z]{1}))/i',function($matches){
return strtoupper($matches[2]);
},$str);
}
怪我咯2017-04-10 14:59:44
function camelCase($value){
$studly = ucwords(str_replace(array('-', '_'), ' ', $value));
return str_replace(' ','',lcfirst($studly));
}
echo camelCase('ask-simple-answer');
“ask-simple-answer”转换为“askSimpleAnswer”
这个应该是camel case, 刚好想起laravel有这个函数, 稍作修改,抄过来了