0

嗨,我需要根据这个“动态”分隔符将一个字符串拆分为一个数组:

String   1  String2

String2   65  String3

它的变量之间的数字  ......字符串也可以包含 ,所以 str_replace 或爆炸它是无用的(对我来说)

4

1 回答 1

0
$str = "String   1   ";
$result = preg_split('/   [\d]+  /', $str);
print_r($result);

Array
(
    [0] => String
    [1] =>  
)

解释:

# Match the characters “   ” literally «   »
# Match a single digit 0..9 «[\d]+»
#    Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
# Match the characters “  ” literally «Â  »
于 2011-08-19T07:48:07.460 回答