PHP</br>;小写字母与大写字母相遇的地方

PHP</br>;小写字母与大写字母相遇的地方,php,preg-replace,preg-match,preg-split,Php,Preg Replace,Preg Match,Preg Split,我试图在每个字符前面加上大写字母。我所取得的成就是: $str = "Rating: goodHelps control sebum production Rating: averagePrevents the development of microorganisms in cosmetics Rating: badCan be allergenic Rating: badToxic to cell division"; $string = preg_replace('/([a-z])([

我试图在每个字符前面加上大写字母。我所取得的成就是:

$str =  "Rating: goodHelps control sebum production Rating: averagePrevents the development of microorganisms in cosmetics Rating: badCan be allergenic Rating: badToxic to cell division"; 
$string = preg_replace('/([a-z])([A-Z])/', "</br>", $str);

print_R($string);
$str=“评级:有助于控制皮脂生产评级:平均预防化妆品中微生物的发展评级:badCan过敏评级:badToxic to cell division”;
$string=preg_replace('/([a-z])([a-z])/”,“
”,$str); 打印(字符串);
结果:

评级:goo

elps控制皮脂生成评级:averag

展示化妆品中微生物的发展评级:ba

过敏等级:ba

对细胞分裂有毒性


如您所见,它将删除第一个和第二个字符。我需要一个完整的文本。

您想使用在替换中捕获的内容的反向引用。第一个捕获组
()
$1
,第二个是
$2

$string = preg_replace('/([a-z])([A-Z])/', '$1</br>$2', $str);
$string=preg_replace('/([a-z])([a-z])/','$1
$2',$str);
您希望使用在replace中捕获的内容的反向引用。第一个捕获组
()
$1
,第二个是
$2

$string = preg_replace('/([a-z])([A-Z])/', '$1</br>$2', $str);
$string=preg_replace('/([a-z])([a-z])/','$1
$2',$str);
您可以使用lookaround,这将在小写和大写字符之间插入

$str =  "Rating: goodHelps control sebum production Rating: averagePrevents the development of microorganisms in cosmetics Rating: badCan be allergenic Rating: badToxic to cell division"; 
echo preg_replace('/(?<=[a-z])(?=[A-Z])/', "</br>", $str);
$str=“评级:有助于控制皮脂生产评级:平均预防化妆品中微生物的发展评级:badCan过敏评级:badToxic to cell division”;

echo preg_replace('/(?您可以使用lookaround,这将在小写和大写字符之间插入

$str =  "Rating: goodHelps control sebum production Rating: averagePrevents the development of microorganisms in cosmetics Rating: badCan be allergenic Rating: badToxic to cell division"; 
echo preg_replace('/(?<=[a-z])(?=[A-Z])/', "</br>", $str);
$str=“评级:有助于控制皮脂生产评级:平均预防化妆品中微生物的发展评级:badCan过敏评级:badToxic to cell division”;
echo preg_替换('/(?)?