note 13672 deleted from function.strip-tags by jimw

From: Date: Mon, 29 Oct 2001 01:34:58 +0000
Subject: note 13672 deleted from function.strip-tags by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-19547@lists.php.net to get a copy of this message
I use the following function to remove html codes that I concider "unsafe": function safeHTML($html, $tags = "a|b|br|em|h\d|i|img|p|strong|table|td|th|tr") { // removes all tags that are considered unsafe // why should there be a null character $html = preg_replace('/\0/', '', $html); // convert the ampersants to null characters $html = preg_replace('/\&/', '\0', $html); // convert the sharp brackets to there html code $html = preg_replace('/</', '&lt;', $html); $html = preg_replace('/>/', '&gt;', $html); // restore the tags that are concidered safe if ($tags) { $html = preg_replace("/&lt;($tags.*?)&gt;/i", '<\1>', $html); $html = preg_replace("/&lt;\\/($tags)&gt;/i", '</\1>', $html); } // restore the ampersants $html = preg_replace('/\0/', '&', $html); return($html); } // safeHTML

« previous php.notes (#19547) next »