Code Program

Remove extra Tags from Database Records

Posted on | March 19, 2009 | No Comments

In my database I have many records in which there are html tags and html comments. When I pick description of that data I sometimes got broken html tags as I pick limited characters from that record.

I tried strip_tags function and get rid of problem up to some extent.

<?php

$text = '<p>Test content will go here.</p><!-- Comment --> <a href="#">Other text</a>';

echo strip_tags($text);

//output will be "Test content will go here. Other text"

// and to Allow <p> and <a>

echo strip_tags($text, '<p><a>');

//output will be "<p>Test content will go here.</p> <a href="#">Other text</a>"

?>

Bookmark and Share

Comments

Leave a Reply