(备忘)自己写的UBB2HTML与HTML2UBB函数(2 位领导批示)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
function ubb2html($str)
{
    $str = htmlspecialchars(stripslashes($str));
    // 字体颜色
    $str = preg_replace("#\[color\=([^\]]*)\]([^\[]*)#i","<span style='color:$1'>$2",$str);
    $str = preg_replace("#\[\/color\]#i","</span>",$str);
    // 字体大小
    $str = preg_replace("#\[size\=(\d)\]([^\[]*)#i","<font size='$1'>$2",$str);
    $str = preg_replace("#\[\/size\]#i","</font>",$str);
    // 超链接
    $str = preg_replace("#\[url\=([^\]]*)\]([^\[]*)#i","<a href='$1' target='_blank'>$2",$str);
    $str = preg_replace("#\[\/url\]#i","</a>",$str);
    // 图片
    $str = preg_replace("#\[img\]([^\[]*)\[\/img\]#i","<img src='$1' />",$str);
    // 其它
    $str = preg_replace("#\[([\/]?)b\]#i","<$1strong>",$str);
    $str = preg_replace("#\[([\/]?)i\]#i","<$1i>",$str);
    $str = preg_replace("#\[([\/]?)em\]#i","<$1em>",$str);
    $str = preg_replace("#\[([\/]?)u\]#i","<$1u>",$str);
    return nl2br($str);
}

全文阅读 »

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志