PHP简单字符串过滤方法示例

yipeiwu_com6年前PHP代码库

本文实例讲述了PHP简单字符串过滤方法。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>PHP字符串的过滤方法</title>
</head>
<body>
<?php
function strFilter($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);
  $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);
  $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);
  $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);
  $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);
  $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);
  $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).']结束';
?>
</body>
</html>

效果图如下:

更多关于PHP相关内容感兴趣的读者可查看本站专题:《php安全过滤技巧总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家PHP程序设计有所帮助。

相关文章

详解PHP的Yii框架的运行机制及其路由功能

详解PHP的Yii框架的运行机制及其路由功能

运行机制概述 每一次 Yii 应用开始处理 HTTP 请求时,它都会进行一个近似的流程。 用户提交指向 入口脚本 web/index.php 的请求。 入口脚本会加载 配置数组...

php缓存技术详细总结

php缓存技术详细总结

全页面静态化缓存也就是将页面全部生成html静态页面,用户访问时直接访问的静态页面,而不会去走php服务器解析的流程。此种方式,在CMS系统中比较常见,比如dedecms;一种比较常用的...

PHP中将一个字符串部分字符用星号*替代隐藏的实现代码

有时候我们在开发中会遇到这样一种情况,例如:显示手机号我们需要将中间4位遮挡掉,一般使用“*”号代替,或是显示身份证号码是为了保护个人信息也同样需要遮挡掉4位,故可用到下列方式、代码进行...

PHP下通过系统信号量加锁方式获取递增序列ID

在网上搜了搜,有两个办法但都不太好:一个是简单的以进程ID+时间戳,或进程ID+随机数来产生近似的唯一ID,虽简单但对于追求“完美”的我不愿这样凑合,再说Apache2以后进程会维持相当...

php排序算法(冒泡排序,快速排序)

冒泡排序实现原理 ① 首先将所有待排序的数字放入工作列表中。② 从列表的第一个数字到倒数第二个数字,逐个检查:若某一位上的数字大于他的下一位,则将它与它的下一位交换。 ③ 重复步骤②,直...