下面是过滤特殊的字符串的函数,可以过滤掉文章中的特殊的字符,避免页面出现混乱
希望能有所帮助(原创:小池编程的博客)
//过滤特殊字符
function htmldecode($str) {
if (empty($str)) return;
if ($str == "") return $str;
$str = str_replace("&", chr(34), $str);
$str = str_replace(">", ">", $str);
$str = str_replace("<", "<", $str);
$str = str_replace("&", "&", $str);
$str = str_replace(" ", chr(32), $str);
$str = str_replace(" ", chr(9), $str);
$str = str_replace("'", chr(39), $str);
$str = str_replace("<br />", chr(13), $str);
$str = str_replace("''", "'", $str);
$str = str_replace("select", "set", $str);
$str = str_replace("join", "jon", $str);
$str = str_replace("union", "unon", $str);
$str = str_replace("where", "whe", $str);
$str = str_replace("insert", "inse", $str);
$str = str_replace("delete", "del", $str);
$str = str_replace("update", "upda", $str);
$str = str_replace("like", "lik", $str);
$str = str_replace("drop", "dro", $str);
$str = str_replace("create", "crea", $str);
$str = str_replace("modify", "modi", $str);
$str = str_replace("rename", "renam", $str);
$str = str_replace("alter", "alte", $str);
$str = str_replace("cas", "cas", $str);
$farr = array("/(\s*$)/", "/(<\/*)(img|script|i?frame|style|html|body|title|link|meta|\/?|\/%)([^>]*?)>/isU", "/(<[^>]*)on[a-zA-Z]+\/s*=([^>]*>)/isU");
$tarr = array(" ", " ", //如果要直接清除不安全的标签,这里可以留空
"//1//2");
$str = preg_replace($farr, $tarr, $str);
return $str;
}
转载请注明:小池编程的博客 » php过滤特殊的字符串