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实现下载断点续传的方法

本文实例讲述了PHP实现下载断点续传的方法。分享给大家供大家参考。 具体实现代码如下: 复制代码 代码如下:<?php /*  * PHP下载断点续传 &nbs...

PHP基于简单递归函数求一个数阶乘的方法示例

PHP基于简单递归函数求一个数阶乘的方法示例

本文实例讲述了PHP基于简单递归函数求一个数阶乘的方法。分享给大家供大家参考,具体如下: 一、问题: 求一个数a的阶乘,那么,a!=a*(a-1)*(a-2)*(a-3)*……*2*1....

PHP自定session保存路径及删除、注销与写入的方法

本文实例讲述了PHP自定session保存路径及删除、注销与写入的方法。分享给大家供大家参考。具体方法如下: 复制代码 代码如下: $sessionpath=session_save_p...

PHP如何搭建百度Ueditor富文本编辑器

PHP如何搭建百度Ueditor富文本编辑器

本文为大家分享了PHP搭建百度Ueditor富文本编辑器的方法,供大家参考,具体内容如下 下载UEditor 官网:下载地址 将下载好的文件解压到thinkphp项目中,本文是解压到PU...

PHP array操作10个小技巧分享

1、向array中添加元素 php是一个弱类型语言。因此不必象c语言那样为php array声明长度。向其中添加元素的过程也是声明和初始化的过程。 复制代码 代码如下: $capital...