解决方案 »

  1.   

    $str = '<P>下面我给大家讲讲javascript函数:</P><PRE class=js name="code">&lt;script&gt; <BR>function show() <BR>{ <BR>alert("hello world"); <BR>} <BR>&lt;/script&gt;</PRE><PRE class=js name="code">&lt;script&gt; <BR>function show() <BR>{ <BR>alert("hello world"); <BR>} <BR>&lt;/script&gt;</PRE>
    <P>&nbsp;结果如图:<BR><IMG title=tu1 alt=tu1 src="uploaded/010P0000240111S5344-1.jpg" width=150 height=150 data-mce-src="uploaded/010P0000240111S5344-1.jpg"></P>';
    preg_match_all("/<PRE.*?<\/PRE>/", $str, $matches);
    foreach ($matches[0] as $key => $value) {
    $rep = preg_replace("/<BR>/", '\n', $value);
    $str = str_replace($value, $rep, $str);
    }
    var_dump($str);
      

  2.   

    echo preg_replace_callback('/<pre.+?pre>/is', function($r) { return preg_replace('/<br>/i', "\n", $r[0]); }, $s);