camelCase to dash - two capitals next to each other

前端 未结 2 1032
情话喂你
情话喂你 2021-01-01 23:24

I\'m using this function to convert CamelCase to dashed string:

function camel2dashed($className) {
    return strtolower(preg_replace(\'/([^A-Z-])([A-Z])/\'         


        
2条回答
  •  有刺的猬
    2021-01-02 00:01

    Use a lookahead assertion:

    function camel2dashed($className) {
        return strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $className));
    }
    

    See it working online: ideone

提交回复
热议问题