// 驼峰写法 function toUp ($str) { return preg_replace_callback('/\s(\w)|-(\w)/', function ($matches) { if (count($matches) > 2) { return strtoupper($matches[2]); } return strtoupper($matches[1]); }, $str); }