将首字母大写以“_”分割(两种方式)
2017-11-17 本文已影响0人
苏大发
$str = "WordWordWordWord";
$str_new = preg_replace("/([A-Z])/", "_\\1", $str);
$formatStr = strtolower(substr($str_new,1));
var_dump($str);
echo "<br/>";
print_r($formatStr);
echo "<br/>";
echo "<br/>";
$str="AbcDefGhi";
$array=preg_split("/(?=[A-Z])/",$str);
$b= strtolower(substr(implode("_", $array),1));
print_r($array);
echo "<br/>";
print_r($b);
image.png