PHP下划线转驼峰、驼峰转下划线

    /*
     * 下划线转驼峰
     */
    static function convertUnderline($str)
    {
        $str = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
            return strtoupper($matches[2]);
        }, $str);
        return $str;
    }

    /*
     * 驼峰转下划线
     */
    static function humpToLine($str)
    {
        $str = str_replace("_", "", $str);
        $str = preg_replace_callback('/([A-Z]{1})/', function ($matches) {
            return '_' . strtolower($matches[0]);
        }, $str);
        return ltrim($str, "_");
    }
发布了54 篇原创文章 · 获赞 209 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/qq_34284638/article/details/83348264
今日推荐