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

yipeiwu_com5年前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程序设计有所帮助。

相关文章

Fatal error: session_start(): Failed to initialize storage module: files问题解决方法

之前编译安装的LNMP环境+phpmyamdin4.02的版本,今天突然出现这个问题:复制代码 代码如下:Fatal error: session_start(): Failed to...

php中实现字符串翻转的方法

字符串:$str = "abcdefg"; 方法一(直接使用php自带函数strrev($str)) print_r(strrev($str)); 使用for循环方式,str_split...

php防止用户重复提交表单

php防止用户重复提交表单

我们提交表单的时候,不能忽视的一个限制是防止用户重复提交表单,因为有可能用户连续点击了提交按钮或者是攻击者恶意提交数据,那么我们在提交数据后的处理如修改或添加数据到数据库时就会惹上麻烦。...

php中用memcached实现页面防刷新功能

有个新需求要加上去,防止用户频繁刷新页面。具体需求是当用户在一分钟之后内请求指定的页面超过100次,就直接拒绝请求。仔细分析后发现这个功能用memcache来做最方便: 1、以用户IP和...

php读取文件内容到数组的方法

本文实例讲述了php读取文件内容到数组的方法。分享给大家供大家参考。具体分析如下: php中可以通过file()函数将文件读取到数组中,数组中的元素即为文件的每行,file()函数通过"...