我试图把遇到大写字母的每个字符放在前面。我取得的是:
$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);
结果:
评价:咕
elps 控制皮脂分泌评级:平均
防止化妆品中微生物的滋生 评级:ba
过敏性评级:ba
有氧对细胞分裂
如您所见,它删除了第一个和后面的字符。我需要带有 .
您想对在替换中捕获的内容使用反向引用。第一个捕获组()
是$1
,第二个是$2
:
$string = preg_replace('/([a-z])([A-Z])/', '$1</br>$2', $str);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句