Jump to content


This topic is now archived and is closed to further replies.


Strip HTML help

Recommended Posts


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:[code]<a href=""[/code] ... not closing it. The function will strip EVERYTHING from that point down. Is there anyway to make the function below more dummy proof?[code]$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!!

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.