preg_replace("/(.*<body>)(.*)(</body>.*)/i","\\1"."hahaha"."\\3",$str);

解决方案 »

  1.   

    $string = "<BODY>..</BODY>";
    $newstring = preg_replace("/<BODY>.*<\/BODY>/", "<BODY>aaa</BODY>", $string);
    echo $newstring;
      

  2.   

    to  syre(神仙) 
    $EditorDefault=preg_replace("/(.*<BODY>)(.*)(</BODY>.*)/i","\\1.$EditorDefault.\\3",$contents);
    出错
    Warning: Unknown modifier 'B'
      

  3.   

    那是因为</BODY>前的/要转义
    改成<\/BODY>就可以了
      

  4.   

    能解释一下$EditorDefault=preg_replace("/(<BODY>).*(<\/BODY>)/sU","\\1$EditorDefault\\2",$contents);这句吗?不懂
      

  5.   

    $EditorDefault=preg_replace("/(.*<BODY>)(.*)(<\/BODY>.*)/i","\\1.$EditorDefault.\\3",$contents);
    没出错也是不能替换,但我刚才写出来的那句可以,但我不懂,希望解释一下
      

  6.   

    preg_replace("!<body>(.*)</body>!si","<body>\\1</body>",$str);
    我前面是写错了........