之前有个ASP的替换函数,本想照猫画虎的弄个PHP的,但做出来老是报错,郁闷……
序号  原字符串  替换为1     空格      -
2     /         -
3     %         -
4     !         -
5     +         -
6     \         -7     *           
8     &        
9     #
10    :
11    ?
12    "
13    ,就是这些,前六个替换成-,后边的直接去掉,谢谢啦
搞定立马结贴~

解决方案 »

  1.   


    function files($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 $str;
    }
    哥们不是没自己写,写出来不灵而已~
      

  2.   

    function files($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 $str;
    }
    注意 \ 和 "
    这2个符号 要用反斜杠把它俩转义下
      

  3.   

    <?php
    function replace($str){
    $rstr=<<<EOD
      -
    / -
    % -
    ! -
    + -
    \ -
    *
    &
    #
    :
    ?
    "
    ,
    EOD;
        $a=split("\r\n|\n",$rstr);
        foreach($a as $v){
            $v=trim($v,"\r\n");
            $str=str_replace($v[0],$v[2],$str);
        }
        return $str;
    }
    var_dump(replace("  -[****]"));
    ?>