PHP在线运行
https://c.runoob.com/compile/1/
将驼峰字符串转化为蛇形字符串
php
<?php
function CamelToSnake($camelValue) {
$initValue = preg_replace('/\s+/u', '', $camelValue);
$snakeValue = strtolower(preg_replace('/(.)(?=[A-Z])/u', "$1_", $initValue));
return $snakeValue;
}
// 示例用法
$camelCaseStr = "nameEnglish";
$snakeCaseStr = CamelToSnake($camelCaseStr);
echo $snakeCaseStr; // 输出:name_english
?>