PHP基础知识和操作

PHP在线运行

https://c.runoob.com/compile/1/

https://www.sotool.net/php80

将驼峰字符串转化为蛇形字符串



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
?>

你可能感兴趣的:(php)