Solved

strip html tags except <b></b> and <br /><br>

Posted on 2010-08-27
6
691 Views
Last Modified: 2013-12-13
Hello,

I would like to strip all tags except, <br>, <br /> and <b>.

Is this possible?

<?=$description?>
0
Comment
Question by:movieprodw
6 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 33545168
You can try this:

description = ereg_replace("<[^>]*>", "", $description)
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 33545218
or a simpler version of regex:

$description = strip_tags($description);
0
 
LVL 1

Author Comment

by:movieprodw
ID: 33545255
I know that guys, please understand that I want to KEEP andy <br>, <br /> and <b></b>
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 24

Accepted Solution

by:
mankowitz earned 250 total points
ID: 33545360
strip_tags takes a second argument which is the list of tags not to strip. See http://us3.php.net/strip_tags

$description = strip_tags($description,"<b><br>");
0
 
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 250 total points
ID: 33545362
In that case

strip_tags( $string_to_strip, "<b></b><br/><br>" );

see http://localhost/adummy/docs/ for more info, especially the second parameter.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 33545448
sorry, I misred that question, yes, that exta arg will do it.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

786 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