源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2022-12-27 19:56 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要: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>

效果图如下: [img]http://files.jb51.net/file_images/article/201609/20169494736630.png?2016849484[/img] 更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/336.htm]php安全过滤技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/357.htm]PHP运算与运算符用法总结[/url]》、《[url=http://www.1sucai.cn/Special/495.htm]PHP网络编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/348.htm]PHP基本语法入门教程[/url]》、《[url=http://www.1sucai.cn/Special/339.htm]php操作office文档技巧总结(包括word,excel,access,ppt)[/url]》、《[url=http://www.1sucai.cn/Special/96.htm]php日期与时间用法总结[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部