小弟我不懂正则,请各位高手帮写一下正则,要求是把[e123/]替换成<img src="123.gif" /> ,其中“[e123/]”中的123是动态的。

解决方案 »

  1.   

    你的ubb结构不合适,先把结构重新折腾下吧。建议的格式
      

  2.   

    <?php
    function getIMGString($str) {
    return preg_replace('/\[e(\d+)\/\]/', '<img src="$1.gif" />', $str);
    }$str = '[e123/]' ;
    echo getIMGString($str) ;
    ?>
    D:\PHPnow-1.5.3\php-5.2.9-2-Win32>php test.php
    <img src="123.gif" />
      

  3.   


    $str=preg_replace('/\[e(\d+)\/]/','<img src="$1.gif" />',$str);