php过滤emod与特殊字符

admin4年前php1842
<?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) ;
 ?>


相关文章

面向过程的php sqlhelp

<?php $servername = "localhost"; $username = "root"; $...

php设置16位的md5加密方法

用substr函数实现substr(md5(变量),8,16);就可以实现默认的md5(变量)输出的是32位加密方法...

php.ini 7.3设置

date.timezone = PRCdisplay_errors = On网络保存图片,以及微信获取手机号码: windows下的PHP,只需要到php.ini中把前面的&nb...

php的function函数内部只能有一个return

php的function函数内部只能有一个return,之后的代码就都全部运行不正常了...

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

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

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

php替换ASCIII码空格字符的方法

需要用到PHP自带函数chr()方法如下:$string=str_replace(chr(0x01),"",$string);...

发表评论    

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