mysql如何过滤特殊字符?用PHP语言。高分求助,给补分
展开全部
function deletehtml($str) {
$str = trim($str);
$str = preg_replace("</P>","1234a3211",$str);
$str = preg_replace("</p>","1234a3211",$str);
$str = preg_replace("<br/>","1234a3211",$str);
$str = preg_replace("/<(.[^>]*)>/","",$str);
$str = preg_replace("/([\r\n])[\s]+/","",$str);
$str = preg_replace("/-->/","",$str);
$str = preg_replace("/<!--.*/","",$str);
$str = preg_replace("/&(quot|#34);/","",$str);
$str = preg_replace("/&(amp|#38);/", "/&/",$str);
$str = preg_replace("/&(lt|#60);/", "/</",$str);
$str = preg_replace("/&(gt|#62);/", ">",$str);
$str = preg_replace("/&(nbsp|#160);/", "",$str);
$str = preg_replace("/&(iexcl|#161);/", "/\xa1/",$str);
$str = preg_replace("/&(cent|#162);/", "/\xa2/",$str);
$str = preg_replace("/&(pound|#163);/", "/\xa3/",$str);
$str = preg_replace("/&(copy|#169);/", "/\xa9/",$str);
$str = preg_replace("/(\d+);/", "",$str);
$str = preg_replace("/</", "",$str);
$str = preg_replace("/>/", "",$str);
$str = preg_replace("/\r\n/", "",$str);
$str = preg_replace("/1234a3211/", "/<br/>/",$str);
return $str;
}
$str = trim($str);
$str = preg_replace("</P>","1234a3211",$str);
$str = preg_replace("</p>","1234a3211",$str);
$str = preg_replace("<br/>","1234a3211",$str);
$str = preg_replace("/<(.[^>]*)>/","",$str);
$str = preg_replace("/([\r\n])[\s]+/","",$str);
$str = preg_replace("/-->/","",$str);
$str = preg_replace("/<!--.*/","",$str);
$str = preg_replace("/&(quot|#34);/","",$str);
$str = preg_replace("/&(amp|#38);/", "/&/",$str);
$str = preg_replace("/&(lt|#60);/", "/</",$str);
$str = preg_replace("/&(gt|#62);/", ">",$str);
$str = preg_replace("/&(nbsp|#160);/", "",$str);
$str = preg_replace("/&(iexcl|#161);/", "/\xa1/",$str);
$str = preg_replace("/&(cent|#162);/", "/\xa2/",$str);
$str = preg_replace("/&(pound|#163);/", "/\xa3/",$str);
$str = preg_replace("/&(copy|#169);/", "/\xa9/",$str);
$str = preg_replace("/(\d+);/", "",$str);
$str = preg_replace("/</", "",$str);
$str = preg_replace("/>/", "",$str);
$str = preg_replace("/\r\n/", "",$str);
$str = preg_replace("/1234a3211/", "/<br/>/",$str);
return $str;
}
追问
这个代码写在哪?我不想写在某一个php文件里,我想让着一个文件能够对整个数据库起过滤作用,而不是某一个查询页面
追答
我写这个是过滤数据的。。读出来数据内容,把它里面的html都去了
如deletehtml($content) 就把中的加粗。P标签什么的。都去了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询