如果这样呢?
$Array[0][1] => [One: a]
$Array[0][2] => [Two: b]
$Array[0][3] => [Three: ccc]
$Array[1][1] => [Three: zzz]
$Array[1][2] => [Two: y]用preg_match_all能否做到?排序是小事,最重要把第一维准确分出来
$Array[0][1] => [One: a]
$Array[0][2] => [Two: b]
$Array[0][3] => [Three: ccc]
$Array[1][1] => [Three: zzz]
$Array[1][2] => [Two: y]用preg_match_all能否做到?排序是小事,最重要把第一维准确分出来
$str="[One: a]
[Two: b]
[Three: ccc][Three: zzz]
[Two: y]";preg_match_all("/\[(One|Two|Three):[^\]]+\]/m",$str,$matches);
print_r(array_chunk($matches[0],3));
非得preg_match_all吗
$Array[0][1]="[Two: b]"
$Array[0][2]="[Three: ccc]"
$Array[1][0]="One"
$Array[1][1]="Two"
$Array[1][2]="Three"
$Array[2][0]=""
$Array[2][1]="[Two: y]"
$Array[2][2]="[Three: zzz]"
这是结果,调试环境是php5.14
$pn="#\[(.+?):.+?\](?=(?:.*?\r\n\r\n.*?(\[\\1:.+?\])|.*?\r\n\r\n))#is";
preg_match_all($pn,$str,$ar,PREG_OFFSET_CAPTURE);
print_r($ar);
Array
(
[0] => Array
(
[0] => Array
(
[0] => [One: a]
[1] => 0
) [1] => Array
(
[0] => [Two: b]
[1] => 10
) [2] => Array
(
[0] => [Three: ccc]
[1] => 20
) ) [1] => Array
(
[0] => Array
(
[0] => One
[1] => 1
) [1] => Array
(
[0] => Two
[1] => 11
) [2] => Array
(
[0] => Three
[1] => 21
) ) [2] => Array
(
[0] =>
[1] => Array
(
[0] => [Two: y]
[1] => 50
) [2] => Array
(
[0] => [Three: zzz]
[1] => 36
) ))
PHP Version 5.1.2pcre
PCRE (Perl Compatible Regular Expressions) Support enabled
PCRE Library Version 6.2 01-Aug-2005
Array
(
[0] => Array
(
) [1] => Array
(
) [2] => Array
(
))