This question already has an answer here:
这个问题在这里已有答案:
- php explode string with Uppercase if lowercase letter exists before it without space 1 answer
如果小写字母存在于没有空格1答案之前,php将使用大写字符串爆炸字符串
what i'm trying to make a function
to change the camelcase
variables like "myFullName"
to be readable version. for example if i have varible like this
我正在尝试将函数更改为像“myFullName”这样的camelcase变量为可读版本。例如,如果我有这样的变数
$label = "myFullName"
<!-- expected output is -->
$label = "my full name" ;
1 个解决方案
#1
3
A different approach to REGEX will be to iterate over the word and check if there is an uppercase letter, insert an space before and lowercase the letter
REGEX的另一种方法是迭代单词并检查是否有大写字母,在字母之前插入空格和小写字母
$label = 'myFullName';
$new_word='';
for($i=0, $n=strlen($label); $i<$n; $i++){
$new_word .= strtoupper($label[$i]) == $label[$i]
? ' '.strtolower($label[$i])
: $label[$i];
}
echo $new_word;
//Output
//my full name
#1
3
A different approach to REGEX will be to iterate over the word and check if there is an uppercase letter, insert an space before and lowercase the letter
REGEX的另一种方法是迭代单词并检查是否有大写字母,在字母之前插入空格和小写字母
$label = 'myFullName';
$new_word='';
for($i=0, $n=strlen($label); $i<$n; $i++){
$new_word .= strtoupper($label[$i]) == $label[$i]
? ' '.strtolower($label[$i])
: $label[$i];
}
echo $new_word;
//Output
//my full name