我有以下的话:
$string1 = ucwords("bookingID");
substr(preg_replace("/([A-Z])/", ',\\1', $string1), 1))
输出就像:Booking I D
但如果有两个连续的大写字母,我想避免插入空格。
预期输出:booking ID
如果我输入了像bookingAmountReceived这样的词,那么预期的输出是:Booking Amount Received
答案 0 :(得分:2)
使用量词:
preg_replace("/[A-Z]+/", ",$0", $string1);
答案 1 :(得分:1)
$String = 'bookingAmountReceived';
$Words = preg_replace('/[A-Z][a-z]+/', ' $0 ', ucfirst($String));
echo $Words;
答案 2 :(得分:0)
preg_replace("/[A-Z]+/", " $0", $string1);