Jump to content


Strip HTML help

  • Please log in to reply
1 reply to this topic

#1 redroy

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 13 May 2006 - 11:47 PM


New here... I've got a small problem that I need some help with and have been unsuccessful on other forums. I'm hoping you can point me in the right direction.

What I've got is a content control that I wrote for my clients using php/mysql. I have a function that checks the inserted data and strips out php and unwanted html. The problem is that's too strict. For example if someone makes an error with an acceptable tag like:
<a href=""
... not closing it. The function will strip EVERYTHING from that point down. Is there anyway to make the function below more dummy proof?
$allowedTags = '<h1><h2><h3><h4><h5><h6><b><i><u><a><div><img><ul><li><hr><blockquote>';
$stripAttrib = 'javascript:|onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup';
function stripData($string)
    global $allowedTags, $stripAttrib;
    while($string != strip_tags($string, $allowedTags))
        $string = strip_tags($string, $allowedTags);
    while($string != preg_replace("/$stripAttrib/i", 'FORBIDDEN', $string))
        $string = preg_replace("/$stripAttrib/i", 'FORBIDDEN', $string);
    return $string;

Thanks for your time!!

#2 bcamp1973

  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 23 August 2006 - 04:30 PM

try strip_tags()

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users