$s1 = "hello?jim";
$s2 = "xxxxxhello\?jimxxxxxx";
echo ereg_replace($s1,'xxxx',$s2);
看看

解决方案 »

  1.   

    不行阿,这样倒是行
    $s1 = "hello\?jim";
    $s2 = "xxxxxhello?jimxxxxxx";
    echo ereg_replace($s1,'xxxx',$s2);但是$s1是数据库读出来的,必须自动加上"\",这样很麻烦,我还得为每个通配符都加上\,有没有更好的方法?
      

  2.   

    不行啊,我试过了本函式使需要让资料库处理的字串,引号的部份加上斜线,以供资料库查询 (query) 能顺利运作。这些会被改的字元包括单引号 (')、双引号 (")、反斜线 backslash (\) 以及空字元 NUL (the null byte)。好象问号不算阿~
      

  3.   

    QuoteMeta
    加入引用符号。语法: string quotemeta(string str);传回值: 字串函式种类: 资料处理
     
     
    内容说明 
    本函式将字串中含有 . \\ + * ? [ ^ ] ( $ ) 等字元的前面加入反斜线 "\" 符号。