Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
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…

792 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