Php Preg_替换为内支架[]

Php Preg_替换为内支架[],php,regex,Php,Regex,我现在使用preg_replace创建一个短代码 浏览器的输出将显示: Below content will be hidden. <div class="lock" style="display:none"> Code Vip: Write something here. </div> [social lock]-[/social lock]中的内容应该隐藏,但不是。我认为这是因为短代码内容中的括号[]。 但我找不到解决办法 它会中断,因为您使用[^[]*表示除[0

我现在使用preg_replace创建一个短代码

浏览器的输出将显示:

Below content will be hidden. 
<div class="lock" style="display:none">
Code Vip: Write something here.
</div>
[social lock]-[/social lock]中的内容应该隐藏,但不是。我认为这是因为短代码内容中的括号[]。
但我找不到解决办法

它会中断,因为您使用[^[]*表示除[0到无限次之间]以外的所有字符。因此它会在字符串中的[1]处停止


要解决这个问题,您可以使用。*?,它表示获取0到无限次之间的所有内容,但是是惰性的。还要确保设置标志s,这样。还可以在新行上进行匹配。

我的代码还替换了[social lock]我试过了。*?但是运气不好。@AlumumGates正如我所说,你还需要设置标志s:你救了我的命!我忘了/s。谢谢!
Below content will be hidden. 

[social-lock]
Code Vip: Write something here.
[/social-lock].
Below content will be hidden. 
<div class="lock" style="display:none">
Code Vip: Write something here.
</div>
Below content will be hidden. 

[social-lock]
Code Vip: Write something here. [show the brackets here]
and it will not be hidden.
[/social-lock].