Skip to content

Instantly share code, notes, and snippets.

@sandyUni
Last active December 29, 2015 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandyUni/7643928 to your computer and use it in GitHub Desktop.
Save sandyUni/7643928 to your computer and use it in GitHub Desktop.
过滤部分标签
<?php
function delTags($str)
{
$farr = array(
"/<(\/?)(script|i?frame|style|html|body|title|link|meta|form|input|embed|object|textarea|\?|\%)([^>]*?)>/isU",
"/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU"
);
$tarr = array(
"",
""
);
$str = preg_replace( $farr,$tarr,$str);
return $str;
}
$str = "<a href='#'>asdfasdfsd</a>====<script>alert(1111)</script>";
echo delTags($str); //结果:<a href='#'>asdfasdfsd</a>====alert(1111)
echo strip_tags($str); //结果:sdfasdfsd====alert(1111)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment