开发者

How to remove custom tag in PHP?

I am trying to remove following tag from string.

[caption id="attachment_9开发者_如何转开发" align="alignleft" width="137" caption="test"][/caption]

How do I remove it using php's preg_replace?

I tried several regular expression, but failed all.


$output_string = preg_replace('#\[caption[^\]]*\](.*?)\[/caption\]#m', "$1", $input_string)

or if you also want to remove anything between the opening and closing tag, just change "$1" to "".


Here you are:

Tested here: http://www.pagecolumn.com/tool/pregtest.htm

<?php 
$ptn = "/\[caption.+caption\]/";
$str = "Otherstuff[caption id=\"attachment_9\" align=\"alignleft\" width=\"137\" caption=\"test\"][/caption]Something else";
$rpltxt = "@";
echo preg_replace($ptn, $rpltxt, $str);
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜