php mysql查询的时候怎么过滤掉html

php mysql查询的时候怎么过滤掉html,第1张

你这个问题我之前做项目的时候也遇到过,你可以从数据入库时入手解决,具体做法就是你可在把数据存入到数据的时候用strip_tags()函数剥离HTML标签,这样你在查询的时候就不会遇到这种情况了,完全都是数据,如果存入数据库的数据必须要有HTML标记的话那入库的时候可以考虑用htmlspacialchars()函数,希望能够帮到你

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

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/6131248.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-15
下一篇 2023-03-15

发表评论

登录后才能评论

评论列表(0条)

保存