根据大写分割文本块


Split text blocks based on uppercase

我有一个文本块,其中大写文本是摘要,后面跟着详细信息。问题是概要和细节是合并的,我需要拆分它们。由于标题大小不同,我不能使用substr.

下面是原文

 OFF PEAK WEEKS ONLYOnce the property situated in rolling

应该是

 OFF PEAK WEEKS ONLY 
 Once the property situated in rolling

如有任何帮助,不胜感激

$rangeBig = range('A', 'Z');
$rangeLittle = range('a', 'z');
for ($i = 1; $i < strlen($text); $i++)
    if (in_array($text[$i-1], $rangeBig) && in_array($text[$i], $rangeLittle)) {
        $text = substr($text, 0, $i - 1)."'n".substr($text, $i - 1);
        break;
    }

假设真正的文本以大写字母开头:如果最后一个字符是大写字母而实际是小写字母,则在那里插入新行