Solved

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

Posted on 2010-09-07
5
817 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
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 108

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 500 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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 count occurrences of each item in an array.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now