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中对象引用和复制。分享给大家供大家参考,具体如下: 引用 $tv2 = $tv1; 或者 $tv2 = &$tv1; 以上两种方式,效果是一样的。...

小谈php正则提取图片地址

迷上了正则,不断尝试着新花招,首先感谢TNA 的非完全输出RSS,然后再次感谢SH的强迫性学习。没有TNA,我不会去看正则,更不知道世界上有种这么牛的表达式;不是SH的死活说他不懂不知道...

整理的9个实用的PHP库简介和下载

1. ReCAPTCHA The reCAPTCHA 库让你可以为网站创建高级的 CAPTCHA 系统,这个系统其实是用来生成验证信息的,甚至包括语音验证。当然还有 reCAPTCHA...

什么是OneThink oneThink后台添加插件步骤

什么是OneThink oneThink后台添加插件步骤

OneThink以其便捷的建站、丰富的扩展、灵活的二次开发,以及云服务的支持,为广大个人和企业建站带来新的契机和机遇,即将成为互联网新的弄潮儿。 OneThink特性介绍: 1. 基于T...

浅谈PHP中foreach/in_array的使用

php在开发效率很高,这是无可厚非的,但是却是在牺牲执行效率的。php数组功能非常强大,但是也要多加考虑,多试几种情况情况,以防万一,这里,我就简单的说两个遇到的坑,以后如果有发现更多的...