preg_replace("/\[img\]\s*(\S+?)\s*width=(\d*)\s*\[\/img\]/is","<img src=\\1 border=0 width=\2>",$post);

解决方案 »

  1.   

    preg_replace("/\[img\]\s*(\S+?)\s*width=(\d*)\s*\[\/img\]/is","<img src=\\1 border=0 width=\\2>",$post);
      

  2.   

    /\[img\]([^\[]*)\[\/img\]/iUs<img src=\\1 border=0>
      

  3.   

    function my_replace($post){
    if ( preg_match ("/width=\d*/is", $post) ) {
    return preg_replace("/\[img\]\s*(\S+?)\s*width=(\d*)\s*\[\/img\]/is","<img src=\\1 border=0 width=\\2>",$post);
    } else {
    return preg_replace("/\[img\]\s*(\S+?)\s*\[\/img\]/is","<img src=\\1 border=0>",$post);
    }
    }
      

  4.   

    /\[img\]([^\[]*)\[\/img\]/iUs<img src=\\1 border=0>我调试 了一下,上面得可以。谢谢了。
      

  5.   

    正则就是强!
    得学学,今天做一道PHP代码高亮显示的题就因为不会正则卡壳了.