Solved

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

Posted on 2010-09-07
5
824 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 109

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

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 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

10 Experts available now in Live!

Get 1:1 Help Now