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

HTML code converter uses PHP to filter dangerous HTML codes.

WBOY
Release: 2016-07-29 08:38:26
Original
937 people have browsed it

#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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template