\[SECTION\](.*?)\[/SECTION\]
我想这就是你想要的,获得单个SECTION内容的文本?
?
使得*
很懒,所以它只会匹配到当前第一个[/SECTION]
。
例子:
$input = "[CONTENT][SECTION]This is the section C#1[/SECTION][SECTION]This is the section C#2[/SECTION][SECTION]This is the section E #3[/SECTION]";
var_dump(preg_match_all("(\[SECTION\](.*?)\[/SECTION\])",$input,$m),$m);
结果:
int(3)
array(2) {
[0]=>array(3) {
[0]=>string(43) "[SECTION]This is the section C#1[/SECTION]"
[1]=>string(43) "[SECTION]This is the section C#2[/SECTION]"
[2]=>string(43) "[SECTION]This is the section E #3[/SECTION]"
}
[1]=>array(3) {
[0]=> string(24) "This is the section C#1"
[1]=> string(24) "This is the section C#2"
[2]=> string(24) "This is the section E #3"
}
}
哪种语言? – 2012-02-17 15:34:31