Home  >  Article  >  Backend Development  >  Use PHP to filter dangerous HTML code_PHP tutorial

Use PHP to filter dangerous HTML code_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:51:06687browse

#HTML posted by users, filter dangerous codes
function uh($str)
{
$farr = array(
"/\s+/", //Filter excess whitespace
" /<(\/?)(scrīpt|i?frame|style|html|body|title|link|meta|\?|\%)([^>]*?)>/isU", // Filter "/(<[^>]*)on[a -zA-Z]+\s*=([^>]*>)/isU", //Filter the on event of javascrīpt

);
$tarr = array(
" ",
"<\\1\\2\\3>", //If you want to directly clear unsafe tags, you can leave it blank here
"\\1\\2",
);

$str = preg_replace( $farr,$tarr,$str);
return $str;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319187.htmlTechArticle#HTML posted by users, filter dangerous codes functionuh($str) { $farr=array( "/\s+ /",//Filter excess white space"/(\/?)(scrīpt|i?frame|style|html|body|title|link|meta|\?|\%)([^]*?)/isU ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn