php 正则替换

 

// 驼峰写法
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);
}

 

posted @ 2018-04-25 15:37  贝尔塔猫  阅读(137)  评论(0编辑  收藏  举报