php过滤emod与特殊字符

admin1年前php906
<?php 
function xml_entities($string) {
//过滤emod
$ts_zifu= json_encode($string);
$str = json_decode(preg_replace("#(\\\ud[0-9a-f]{3})#i", "", $ts_zifu));
//过滤特殊字符
$text=preg_replace("/[[:punct:]\s]/",' ',$str);
$text=urlencode($text);
$text=preg_replace("/(%7E|%60|%21|%40|%23|%24|%25|%5E|%26|%27|%2A|%28|%29|%2B|%7C|%5C|%3D|\-|_|%5B|%5D|%7D|%7B|%3B|%22|%3A|%3F|%3E|%3C|%2C|\.|%2F|%A3%BF|%A1%B7|%A1%B6|%A1%A2|%A1%A3|%A3%AC|%7D|%A1%B0|%A3%BA|%A3%BB|%A1%AE|%A1%AF|%A1%B1|%A3%FC|%A3%BD|%A1%AA|%A3%A9|%A3%A8|%A1%AD|%A3%A4|%A1%A4|%A3%A1|%E3%80%82|%EF%BC%81|%EF%BC%8C|%EF%BC%9B|%EF%BC%9F|%EF%BC%9A|%E3%80%81|%E2%80%A6%E2%80%A6|%E2%80%9D|%E2%80%9C|%E2%80%98|%E2%80%99|%EF%BD%9E|%EF%BC%8E|%EF%BC%88)+/",' ',$text);
$str=urldecode($text);
//过滤指定的空格与字符
  return   strtr(
        $str, 
        array(
            "<" => "",
            ">" => "",
            '"' => "",
            "'" => "",
            "&" => "",
            "|" => "",
            "-" => "",
            "–" => "",
            ":" => "",
            "Ⅱ" => "2",
            "”" => "",
            "】" => "",
            "【" => "",
            "%" => "",
            "(" => "",
            ")" => "",
            ";" => "",  
            "  " => "",      
        )
    );

}

$string="I love you>>><<,?❤?????‍??????✔?‍??‍???‍?;asdfasdfasdf;";
echo xml_entities($string) ;
 ?>


相关文章

短地址生成,全套配置教程

短地址生成,全套配置教程

nginx 配置location / {rewrite  ^(.*)$  /index.php?s=/$1  last;}code rotoo.top.7z...

php设置跨站访问

  php的open_basedir设置多个路径(目录),分隔符是“:”冒号open_basedir=/www/wwwroot/www.ceshi.com/:/tmp/:/www/...

PHP里面将int型数据转换成日期输出以及将date型数据输出

        echo date('Y-m-d',$date); PHP里面将date型数据输出: echo $date; PHP里面将dat...

批量插入

一条insert语句批量插入多条记录原创|浏览:138554|更新:2017-12-19 08:21一条insert语句批量插入多条记录常见的insert语句,向数据库中,一条语句只能插入一条数据:i...

php再调用json_decode从字符串对象生成json对象时出现Cannot use object of type stdClass as array解决方法

php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误:Cannot use object of type stdClass as array产生...

把字符按照逗号分割成数组

 <?php $cars=$_POST['shuju'];$cars=explode(',', $cars);print_r($cars)&n...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。