我是如何在PHP大写单词中爆炸的? 像:
$text = "HELLO world FROM BRAZIL";
$up = explode(' ',$text);
($up[0] = HELLO, $up[1] = world, $up[2] = FROM BRAZIL)
由于
答案 0 :(得分:5)
您需要将字符串作为一个整体进行爆炸,然后循环遍历数组并使用ctype_upper()
进行测试。
$text = "HELLO world FROM BRAZIL";
$up = explode(' ',$text);
foreach($up AS $value){
if (ctype_upper($value)) {
echo $value;
}
}
答案 1 :(得分:4)
不要使用explode()
,请尝试preg_split()
:
$up = preg_split('/\s([^A-Z]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
答案 2 :(得分:0)
$str = "ThisIsA STRING"
echo preg_replace('/([a-z])([A-Z])/','$1 $2', $str)
This Is A STRING