preg_replace help

Hello experts,

I'm struggling with preg_replace(), could you help me? I have a file that contains the following text, how do I use preg_replace to remove "[sidebar]" and "[/sidebar]", including all the text between the two tags? The text between the tags will vary, and I want to get rid of all of it.

[sidebar]
Grab this cool stuff for your site
Text is variable!
[/sidebar]

Open in new window



Thank you!
EffinGoodAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Terry WoodsConnect With a Mentor IT GuruCommented:
This should do it:
$text = preg_replace("#\[sidebar\].*?\[/sidebar\]#s","",$text);

Open in new window


The s pattern modifier at the end of the pattern string means the . wildcard will match \n characters as well as everything else, which allows the matched text to span multiple lines.
0
 
EffinGoodAuthor Commented:
Thank you Terry!
0
All Courses

From novice to tech pro — start learning today.