$txt = preg_replace( "/\[\/wav\]/", "[/player]", $txt );

解决方案 »

  1.   

    <?php
    $txt="[wav]http://www.xxx.com/1.mp3[/wav]";
    $txt = preg_replace( "/\wav/", "player", $txt );
    echo $txt;
    ?>
      

  2.   

    <?php
    $txt="[wav]http://www.xxx.com/1.mp3[/wav]";
    $txt = preg_replace( "/\wav/", "player", $txt );
    echo $txt;
    ?>
      

  3.   

    这样写好一点:
    $txt = preg_replace( "/\wav]/", "player]", $txt );
      

  4.   

    这样会更好更安全:<?php
    $txt="[wav]http://www.xxx.com/1.mp3[/wav]";
    $txt = preg_replace("/\[(\/)?wav]/gi", "[\\1player]", $txt);
    echo $txt;
    ?>
      

  5.   

    $txt = preg_replace("/\[(\/)?wav]/i", "[\\1player]", $txt);
    楼上多了一个g吧 :)
      

  6.   

    非常感谢上面几位的帮忙,谢谢!
    现在我又遇到些问题,就是这种形式的串:
    <!--Image http://fef.com/cfds.jpg--><a href='http://fef.com/cfds.jpg' target='_blank'><img src='http://fef.com/cfds.jpg' border='0' alt='用户发表的图象' onload='javascript:if(this.width>(screen.width*0.8-400)) this.width=(screen.width*0.8-400)'></a><!--End Image-->转换成这样的形式这个真是太难了!!大家看看呀!
      

  7.   

    echo preg_replace("/^\[wav\](.+)\[\/wav\]/","[player]\\1[/player]","[wav]http://www.xxx.com/1.mp3[/wav]");$str="<!--Image http://fef.com/cfds.jpg--><a href='http://fef.com/cfds.jpg' target='_blank'><img src='http://fef.com/cfds.gif' border='0' alt='用户发表的图象' onload='javascript:if(this.width>(screen.width*0.8-400)) this.width=(screen.width*0.8-400)'></a><!--End Image-->";
    if(preg_match("/href=['|\"](.+)['|\"].+src=['|\"](.+)['|\"]/iU",$str,$pats))
    {
    echo "".$pats[1]."][IMG]".$pats[2]."[/IMG";
    }
      

  8.   

    echo preg_replace("/^\[wav\](.+)\[\/wav\]/","[player]\\1[/player]","[wav]http://www.xxx.com/1.mp3[/wav]");$str="<!--Image http://fef.com/cfds.jpg--><a href='http://fef.com/cfds.jpg' target='_blank'><img src='http://fef.com/cfds.gif' border='0' alt='用户发表的图象' onload='javascript:if(this.width>(screen.width*0.8-400)) this.width=(screen.width*0.8-400)'></a><!--End Image-->";
    if(preg_match("/href=['|\"](.+)['|\"].+src=['|\"](.+)['|\"]/iU",$str,$pats))
    {
    echo "".$pats[1]."][IMG]".$pats[2]."[/IMG";
    }