preg_match表现得很奇怪

Sim*_*son 5 php regex preg-replace

preg_match()用来从变量中提取文本片段,让我们说变量看起来像这样:

[htmlcode]This is supposed to be displayed[/htmlcode]

middle text

[htmlcode]This is also supposed to be displayed[/htmlcode]
Run Code Online (Sandbox Code Playgroud)

我想提取[htmlcode]'s 的内容并将它们输入到数组中.我这样做是通过使用preg_match().

preg_match('/\[htmlcode\]([^\"]*)\[\/htmlcode\]/ms', $text, $matches);
foreach($matches as $value){
return $value . "<br />";
}
Run Code Online (Sandbox Code Playgroud)

上面的代码输出

[htmlcode]This is supposed to be displayed[/htmlcode]middle text[htmlcode]This is also supposed to be displayed[/htmlcode]
Run Code Online (Sandbox Code Playgroud)

代替

  1. [htmlcode]这应该显示[/ htmlcode]
  2. [htmlcode]这也应该显示[/ htmlcode]

如果真的没有想法