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.
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 ""
.