http://zwills.crcoo.com/mikespook/softlist.asp?id=68UBB 代码~~

解决方案 »

  1.   

    UBB替换代码~~~function h2t($d){
    $d=str_replace("<","&lt;",$d);
    $d=str_replace(">","&gt;",$d);
    $d=str_replace("|","│",$d);
    $d=str_replace("\r","",$d);
    $d=str_replace("\t","",$d);
    $d=str_replace("\n","<br>",$d);
    $d=str_replace(" ","&nbsp;",$d);
    $pattern = array(
    "/\[b\](.+?)\[\/b\]/is",
    "/\[i\](.+?)\[\/i\]/is",
    "/\[u\](.+?)\[\/u\]/is",
    "/\[font=([^\[]*)\](.+?)\[\/font\]/is",
    "/\[color=([#0-9a-z]{1,10})\](.+?)\[\/color\]/is",
    "/\[size=([0-9]{1,2})\](.+?)\[\/size\]/is",
    "/\[email=([^\[]*)\](.+?)\[\/email\]/is",
    "/\[email\]([^\[]*)\[\/email\]/is",
    "/\[url=([^\[]*)\](.+?)\[\/url\]/is",
    "/\[url\]www\.([^\[]*)\[\/url\]/is",
    "/\[url\]([^\[]*)\[\/url\]/is",
    "/\[fly\](.+?)\[\/fly\]/is",
    "/\[move\](.+?)\[\/move\]/is",
    "/\[align=(left|center|right)\](.+?)\[\/align\]/is",
    "/\[shadow=([#0-9a-z]{1,10})\,([0-9]{1,3})\,([0-9]{1,2})\](.+?)\[\/shadow\]/is",
    "/\[glow=([#0-9a-z]{1,10})\,([0-9]{1,2})\](.+?)\[\/glow\]/is",
    "/\[code\](.+?)\[\/code\]/is",
    "/\[list\](.+?)\[\/list\]/is",
    "/\[list=([aA1iI])\](.+?)\[\/list\]/is",
    "/\[\*\](.*?)/i",
    );
    $replacement = array(
      "<b>\\1</b>",
      "<i>\\1</i>",
      "<u>\\1</u>",
      "<font face=\"\\1\">\\2</font>",
    "<font color=\"\\1\">\\2</font>",
    "<font size=\"\\1\">\\2</font>",
    "<a href=\"mailto:\\1\">\\2</a>",
    "<a href=\"mailto:\\1\">\\1</a>",
    "<a href=\"\\1\" target=_blank>\\2</a>",
    "<a href=\"http://www.\\1\" target=_blank>\\1</a>",
    "<a href=\"\\1\" target=_blank>\\1</a>",
    "<marquee width=90% behavior=alternate scrollamount=3>\\1</marquee>",
    "<marquee scrollamount=3>\\1</marquee>",
    "<div align=\\1>\\2</div>",
    "<table width=*><tr><td style=\"filter:shadow(color=\\1, direction=\\2 ,strength=\\3)\">\\4</td></tr></table>",
    "<table width=*><tr><td style=\"filter:glow(color=\\1, strength=\\2)\">\\3</td></tr></table>",
    "<blockquote><b>代码:</b><hr color=#990000><font face='Courier New'>\\1</font><hr color=#990000></blockquote>",
    "<ul>\\1</ul>",
    "<ol type=\\1>\\2</ol>",
    "<li>\\1</li>"
    );
    $d = preg_replace($pattern,$replacement,$d);
    $d = preg_replace("/\[img\]\s*(\S+?)\s*\[\/img\]/is","<a href=\\1 target=_blank title=\"贴图:点击放大查看\"><img src=\\1 border=0 onload=\"javascript:if(this.width>500)this.width=300\"></a>",$d);
    return $d;
    }
      

  2.   

    只是一个函数而已~~~比如你的留言板要插入图片~使用UBB代码~~~然后留言板就有图片显示~~~$str="留言";
    h2t($str)返回的就是转换后的~
      

  3.   

    HOHO,这个我倒是知道~只是想知道这个函数这么写什么意思?正则?
      

  4.   

    是正则表达式~~~用 $replacement 中对应项替换 $pattern 中的内容。这样就可以实现UBB代码到HTML代码的转换~~
      

  5.   

    ASPif xxx then 
      response.write ""
    end if