如果规则为“,{CAPITAL LETTER}”,如何拆分字符串

时间:2018-05-03 07:31:38

标签: php

我想知道如何将以下字符串拆分为数组:

带两个臂式卷发器,腿部卷发器和杠铃架的训练台,Max。载荷:160kg

输出应为:

array (
[0] => 'Training bench with two arm curlers, leg curler and barbell rack',
[1] => 'Max. load: 160kg'
);

规则可以是“,{CAPITAL LETTER} ”(逗号+空格+大写字母)。 在这种情况下,“ ,M '

你可以告诉我吗?

谢谢。

1 个答案:

答案 0 :(得分:3)

这可按要求运作

$str = "Training bench with two arm curlers, leg curler and barbell rack, Max. load: 160kg";
print_r(preg_split('/\,\ (?=[A-Z])/m',$str));

输出:

Array
(
    [0] => Training bench with two arm curlers, leg curler and barbell rack
    [1] => Max. load: 160kg
)