从am string中删除[caption] [/ caption]

时间:2016-04-12 12:57:06

标签: php regex php-5.3

假设我有字符串

test [caption id="attachment_13399" align="alignleft" width="240"]<img class="img" src="test.jpg" alt="Test Image" width="240" height="270" /> Test remove capture[/caption] end test

我需要在preg_replace之后才显示:test end test

但我得test Test remove capture end test

我的正则表达式是:$text = preg_replace('/\[.*?\]/', '', $a_record['content'])

你能帮帮我吗? Thx提前和抱歉我的英语

1 个答案:

答案 0 :(得分:1)

将其更改为:

/\\[caption.*?\\].*\\[.caption\\]/

这将删除[caption][/caption]

之间的所有内容