?
Solved

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

Posted on 2010-09-07
5
Medium Priority
?
832 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

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

801 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