Home  >  Article  >  Backend Development  >  PHP simple string filtering method example sharing

PHP simple string filtering method example sharing

墨辰丷
墨辰丷Original
2018-06-01 14:08:261724browse

这篇文章主要介绍了PHP简单字符串过滤方法,结合实例形式分析了php通过对字符串中特殊字符进行正则替换实现字符过滤功能的简单操作技巧,需要的朋友可以参考下

具体如下:







PHP字符串的过滤方法

', '', $str); $str = str_replace('《', '', $str); $str = str_replace('》', '', $str); $str = str_replace('.', '', $str); $str = str_replace('。', '', $str); $str = str_replace('/', '', $str); $str = str_replace('、', '', $str); $str = str_replace('?', '', $str); $str = str_replace('?', '', $str); //防sql防注入代码的过滤方法 $str = str_replace('and','',$str); $str = str_replace('execute','',$str); $str = str_replace('update','',$str); $str = str_replace('count','',$str); $str = str_replace('chr','',$str); $str = str_replace('mid','',$str); $str = str_replace('master','',$str); $str = str_replace('truncate','',$str); $str = str_replace('char','',$str); $str = str_replace('declare','',$str); $str = str_replace('select','',$str); $str = str_replace('create','',$str); $str = str_replace('delete','',$str); $str = str_replace('insert','',$str); $str = str_replace('or','',$str); return trim($str); } $cont = ' ?”?;onestopweb.cn and update //\ as chaoyi 》、 '; echo '开始['.strFilter($cont).']结束'; ?>


效果图如下:


总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。

相关推荐:

php插入含有特殊符号数据的处理方法

php监测数据是否成功插入到Mysql数据库的方法

php实现的网页版剪刀石头布游戏

The above is the detailed content of PHP simple string filtering method example sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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