我如何爆炸PHP大写单词? 像:PHP爆炸大写单词
$text = "HELLO world FROM BRAZIL";
$up = explode(' ',$text);
($up[0] = HELLO, $up[1] = world, $up[2] = FROM BRAZIL)
感谢
我如何爆炸PHP大写单词? 像:PHP爆炸大写单词
$text = "HELLO world FROM BRAZIL";
$up = explode(' ',$text);
($up[0] = HELLO, $up[1] = world, $up[2] = FROM BRAZIL)
感谢
不要使用explode()
,尝试preg_split()
:
$up = preg_split('/\s([^A-Z]+)/', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
谢谢你!作品! – Luc4s
您需要爆炸字符串作为一个整体,然后通过数组和测试与ctype_upper()
循环。
$text = "HELLO world FROM BRAZIL";
$up = explode(' ',$text);
foreach($up AS $value){
if (ctype_upper($value)) {
echo $value;
}
}
$str = "ThisIsA STRING"
echo preg_replace('/([a-z])([A-Z])/','$1 $2', $str)
This Is A STRING
不要使用'explode' – AbraCadaver