大驼峰转点链接
2018-11-17 本文已影响0人
笺戈浅
$path ="IndexController@inex";
$current = '';//定义一个空字符串
//循环目标字符串
for ($i = 0; $i < strlen($path); $i++) {
$s = $path{$i};//获取当前一个字符
//转指定非标准大写字符
if ($s == '@') {
$current .= ".";
} else {
//计算ASCII值,来判断是否是大写并且是大驼峰首字符
if (ord($s) > 64 && ord($s) < 91 && $i == 0) {
$current .= strtolower($s);//是大写,转成小写,前面追加符号
} else {
//计算ASCII值,来判断是否是大写
if (ord($s) > 64 && ord($s) < 91) {
$current .= ".".strtolower($s);
} else {
$current .= $s;
}
}
}
}
echo PHP_EOL,$current,PHP_EOL;