如何使用正则完成驼峰转下划线
1、驼峰转下划线命名方式有几种,小编在下面会一次讲解

2、第一种方法:
function HumpToUnderline1($str){
$str = preg_replace_callback('/([A-Z]{1})/',function($matches){
return '_'.strtolower($matches[0]);
},$str);
return trim($str,'_');
}

3、第二种方法:
function HumpToUnderline2($camelCaps,$separator='_'){
return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
}

4、第三种方法:
function HumpToUnderline3($str){
$dstr = preg_replace_callback('/([A-Z]+)/',function($matchs){
return '_'.strtolower($matchs[0]);
},$str);
return trim(preg_replace('/_{2,}/','_',$dstr),'_');
}

5、使用:
public function change(){
echo $this->HumpToUnderline1("testStringHello");
echo "<br />";
echo $this->HumpToUnderline2("testStringHello");
echo "<br />";
echo $this->HumpToUnderline3("testStringHello");
}
