PHP驼峰转下划线

/**
 * @notes: 驼峰转下划线
 * @param string|null $string
 * @return string
 */
function convert_to_underscore(string|null $string)
{
    if (empty($string)) {
        return '';
    }
    $pattern     = '/([a-z])([A-Z])/';
    $replacement = '${1}_${2}';
    return strtolower(preg_replace($pattern, $replacement, $string));
}

  

posted @ 2024-09-21 15:36  橙子与柠檬  阅读(17)  评论(0)    收藏  举报