0

我有如下的话:

$string1 = ucwords("bookingID");
substr(preg_replace("/([A-Z])/", ',\\1', $string1), 1))

输出如下:Booking I D

但如果有两个连续的大写字母,我想避免插入空格。

预期输出:booking ID

如果我输入像 bookingAmountReceived 这样的词,那么预期的输出是:Booking Amount Received

4

3 回答 3

2

使用量词:

preg_replace("/[A-Z]+/", ",$0", $string1);
于 2013-01-29T05:42:50.677 回答
1
$String = 'bookingAmountReceived';
$Words = preg_replace('/[A-Z][a-z]+/', ' $0 ', ucfirst($String));
echo $Words;
于 2013-01-29T05:47:16.277 回答
0
preg_replace("/[A-Z]+/", " $0", $string1);
于 2013-01-29T05:44:59.747 回答