]*?)>/isU", //Filter ]*?)>/isU", //Filter

Home  >  Article  >  Backend Development  >  HTML code converter uses PHP to filter dangerous HTML codes.

HTML code converter uses PHP to filter dangerous HTML codes.

WBOY
WBOYOriginal
2016-07-29 08:38:26863browse

#HTML posted by users, filter dangerous codes
function uh($str)
{
$farr = array(
"/\s+/", //Filter excess white space
"/<(\/?)(scrīpt |i?frame|style|html|body|title|link|meta|\?|\%)([^>]*?)>/isU", //Filtering "/(<[^>]*)on[a-zA-Z]+\s*=([ ^>]*>)/isU", //Filter the on event of javascrīpt
);
$tarr = array(
" ",
"<\\1\\2\\3>", //If To directly clear unsafe tags, you can leave it blank here
"\\1\\2",
);
$str = preg_replace( $farr,$tarr,$str);
return $str;
}

The above has introduced the HTML code converter function that uses PHP to filter dangerous HTML codes, including the content of the HTML code converter. I hope it will be helpful to friends who are interested in PHP tutorials.

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