Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

preg_replace help

Posted on 2013-11-13
2
Medium Priority
?
322 Views
Last Modified: 2013-11-13
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!
0
Comment
Question by:EffinGood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 39646765
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
 

Author Closing Comment

by:EffinGood
ID: 39646775
Thank you Terry!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question