怎么用PHP来过滤输入的内容中包含的元字符

解决方案 »

  1.   

    需要过滤什么元字符使用\来解决 例如 '/\?+/',$str
      

  2.   

    洒家对此极为擅长。洒家来助你。
    好汉,你要实现何功能?正则表达式
    ()
    贪婪.*
    不贪婪.*?
    安行u
    区分大小写i查找用preg_match(正则,目标,结果仍一数组)
    替换用preg_replace(正则,目标,源)
      

  3.   


    //过滤非法字符
    $badwords="!=,@=,#=,$=,%=,&=,*=,\=,。=,`=";
    function filter_badwords($content,$badwords){
    $words=explode(",",$badwords);
    $words_count=count($words);
    $words_tmep=$content;
    for($i=0;$i<$words_count;$i++){
    $replace_tmep=explode("=",$words[$i]);
    $words_tmep=str_replace($replace_tmep[0],$replace_tmep[1],$words_tmep);
    }
    return $words_tmep;
    }
    使用时传入$content就可以了, 可以根据自己的需要修改$badwords
    功能是把$content中出现的等号左侧的字符换成等号右侧的字符。
      

  4.   

    正则,正则,正则。。http://www.yesky.com/imagesnew/software/vbscript/html/jsgrpRegExpSyntax.htm