note 13672 deleted from function.strip-tags by jimw
| From: | jimw@php.net | 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('/</', '<', $html);
$html = preg_replace('/>/', '>', $html);
// restore the tags that are concidered safe
if ($tags) {
$html = preg_replace("/<($tags.*?)>/i", '<\1>', $html);
$html = preg_replace("/<\\/($tags)>/i", '</\1>', $html);
}
// restore the ampersants
$html = preg_replace('/\0/', '&', $html);
return($html);
} // safeHTML