PHP字符串中特殊符号的过滤方法介绍

yipeiwu_com6年前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);
    return trim($str);
}

相关文章

基于递归实现的php树形菜单代码

本文实例讲述了基于递归实现的php树形菜单代码。分享给大家供大家参考。具体实现方法如下: 开发电子商务网站的时候,做了这个显示树形菜单的功能,用的递归实现的PHP树形菜单函数。具体代码如...

PHP 作用域解析运算符(::)

Scope Resolution Operator (::) 今天 看joomla源码的时候,才意识到。原来这个操作符还可以访问类的非静态方法啊。真的让我吃惊不好。一直以为作用域解析运算...

PHP实现动态压缩js与css文件的方法

本文实例讲述了PHP实现动态压缩js与css文件的方法。分享给大家供大家参考,具体如下: 正式发布产品时,我们希望将项目里的js,css合并压缩,以减少http请求、防止轻易查看源代码。...

iis6手工创建网站后无法运行php脚本的解决方法

iis6手工创建网站后无法运行php脚本的解决方法

给人搬了十几个网站,老站用西部数码建站助手创建的,现在过期了无法继续创建,只能在Internet 信息服务(IIS)管理器创建网站,创建下来都没问题,但是就是无法打开网站。 测试打开tx...

PHP不使用内置函数实现字符串转整型的方法示例

PHP不使用内置函数实现字符串转整型的方法示例

介绍 php字符串类型的数字如果想转成整型的数字,一般我们都是采用系统内置的API去做转换,但如果规定就不让我们去用系统内置的API转换,而是让自己去实现一个函数转换该怎么办?这里我们看...