不会用preg_replace,那位帮写一下代码!
将HTML文件中的类似下面这段:<div id="r_tx不确定的数字" style="width:100%">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td>
                        <a id="r1_t" href="http://www.xxx.com/xx/xxxxx.html" onmousedown="return fp(this,{en:'te',io:'x',x:'xxx',tp:'d',ec:'x',ex:'tsrc%3Dtxtx'},'false',0)"
                           class="L4" >xxx xxxxx xxxxxx xxx xxxx xxxxx</a>
            </td>
        </tr>
    </table>
</div>替换为:<div id="r_tx不确定的数字" style="width:100%">
<a onClick="openwin('http://www.xxx.com/xx/xxxxx.html')" href="#">xxx xxxxx xxxxxx xxx xxxx xxxxx</a>
</div>需要多次替换,X表示不确写的内容

解决方案 »

  1.   

    <?php
    $str =<<<HTML
    <div id="r_tx不确定的数字" style="width:100%"> 
        <table cellpadding="0" cellspacing="0"> 
            <tr> 
                <td> 
                            <a id="r1_t" href="http://www.xxx.com/xx/xxxxx.html" onmousedown="return fp(this,{en:'te',io:'x',x:'xxx',tp:'d',ec:'x',ex:'tsrc%3Dtxtx'},'false',0)" 
                              class="L4" >xxx xxxxx xxxxxx xxx xxxx xxxxx </a> 
                </td> 
            </tr> 
        </table> 
    </div> 
    HTML;
    $reg = '/<table.+?<a.+?href="(.+?)".+?>(.+?)<\/a>.+<\/table>/is';
    echo preg_replace($reg,'<a onclick="openwin(\'$1\')" href="#">$2</a>', $str);
    ?>
      

  2.   

    <?php
    $str =<<<HTML
    <div id="r_tx不确定的数字" style="width:100%"> 
        <table cellpadding="0" cellspacing="0"> 
            <tr> 
                <td> 
                            <a id="r1_t" href="http://www.xxx.com/xx/xxxxx.html" onmousedown="return fp(this,{en:'te',io:'x',x:'xxx',tp:'d',ec:'x',ex:'tsrc%3Dtxtx'},'false',0)" 
                              class="L4" >xxx xxxxx xxxxxx xxx xxxx xxxxx </a> 
                </td> 
            </tr> 
        </table> 
    </div> 
    HTML;
    $reg = '/<table.+<a.+?href="(.+)".+>(.+)<\/a>.+<\/table>/isU';
    echo preg_replace($reg,'<a onclick="openwin(\'$1\')" href="#">$2</a>', $str);
    ?>
      

  3.   

    以这个为准,汗~
    <?php
    $str =<<<HTML
    <div id="r_tx不确定的数字" style="width:100%"> 
        <table cellpadding="0" cellspacing="0"> 
            <tr> 
                <td> 
                            <a id="r1_t" href="http://www.xxx.com/xx/xxxxx.html" onmousedown="return fp(this,{en:'te',io:'x',x:'xxx',tp:'d',ec:'x',ex:'tsrc%3Dtxtx'},'false',0)" 
                              class="L4" >xxx xxxxx xxxxxx xxx xxxx xxxxx </a> 
                </td> 
            </tr> 
        </table> 
    </div> 
    HTML;
    $reg = '/<table.+<a.+href="(.+)".+>(.+)<\/a>.+<\/table>/isU';
    echo preg_replace($reg,'<a onclick="openwin(\'$1\')" href="#">$2</a>', $str);
    ?>
      

  4.   

    谢谢 cgisir(老韩) !用你的代码试了一下,需要替换的部分是替换成功了,但把其它需要保留的内容也替换掉了