php - 如何防止字符串中的大写缩略语中的单词中断

时间:2013-01-29 05:40:39

标签: php codeigniter

我有以下的话:

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

输出就像:Booking I D

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

预期输出:booking ID

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

3 个答案:

答案 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);