\[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