PHP工具-驼峰下划线互转
2018-07-26 本文已影响6人
保儿洁
<?php
function lineToHump($str)
{
return preg_replace_callback('/(_[a-z])/', function ($match) {
return ucfirst(trim($match[0], '_'));
}, $str);
}
function humpToLine($str)
{
return preg_replace_callback('/([A-Z])/', function ($match) {
return '_' . lcfirst($match[0]);
}, $str);
}
echo lineToHump("new_id");
echo "\n";
echo humpToLine("newId");
newId
new_id