Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP function to clean string from HTML tags except url and strong tag.

Posted on 2010-09-07
5
Medium Priority
?
833 Views
Last Modified: 2013-12-13
Hi,

Does someone knows a php function to clean a php string from all tags except links and bold text?

Please help.
Thank you.
0
Comment
Question by:Fernanditos
[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
5 Comments
 
LVL 3

Expert Comment

by:DanMerk
ID: 33621279
You can use the trim command and pass it everything that should be trimmed via the second parameter.

http://php.net/manual/en/function.trim.php
0
 

Author Comment

by:Fernanditos
ID: 33622252
Trim was not exactly the solution. I found strip_tags do it great.


<?php echo strip_tags($row_rsPage['body_pnas_en'], '<p><a><br><li><strong>'); ?>

Open in new window

0
 
LVL 3

Expert Comment

by:yudohartono
ID: 33624386

htmlentities,htmlspecialchars

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 33631934
You're on firm ground with strip_tags() but please read the warnings on the man page.  See also this note:
http://us.php.net/manual/en/function.strip-tags.php#88991

Best regards, ~Ray
0
 
LVL 8

Accepted Solution

by:
kumaranmca earned 2000 total points
ID: 33643466
refer my below code...

also below refer url... http://php.net/manual/en/function.strip-tags.php
<?php
$text = 'http://www.google.com<strong>Test paragraph.</strong><!-- Comment --> <a href="#fragment">Other text</a>';
//echo strip_tags($text);
//echo "\n";

// Allow <p> and <a>
echo strip_tags($text, '<strong><a>');
?>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

610 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