Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

strip tags

Status
Not open for further replies.

manicleek

Technical User
Jun 16, 2004
143
GB
I am using the strip tags function with a few allowed tags, but some are causing problems when the data is out-putted.

in particular when I allow <table> <tr> <td> <ul> and <li>

my code is

strip_tags($OnFeature["contmain"], '<a><strong><table><td><tr><li><ul>')
 
try this:
Code:
<?
function StripIt($TheStr)
{
 $TheStr=preg_replace("/<[^\s]*?>/U","",$TheStr);
 return $TheStr;
}
$str="<table><hr>All the tags<b> here</b><ul><ANYTAG></table>";
echo StripIt($str);
?>

Known is handfull, Unknown is worldfull
 
C ould elaborate on what kind of problems you encounter?
 
Thanks vbkris but that didn't seem to work

I have a database that has feature stories in a mediumtext field.

Some of the stories have items laid out in a table or with bullet points, with the html code entered in amongst the story which would work fine but I have to use strip_tags() on the output for various reasons.

I have tried using the above strip_tags bit of code to allow <table> etc... but it throws the formatting out.

e.g. when there is a table it puts a large amount of space between the top of the table and the text above it or with the bullet point tags the bullet points don't appear and all the normal text below the list loses its formatting, i.e. css etc...
 
i am confused, my function strips ALL html tags, why not use it on the output from the database?

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top