欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php实现过滤UBB代码的类

程序员文章站 2023-10-17 13:09:18
本文实例讲述了php实现过滤ubb代码的类。分享给大家供大家参考。具体如下: php代码如下: 复制代码 代码如下:class day{    f...

本文实例讲述了php实现过滤ubb代码的类。分享给大家供大家参考。具体如下:

php代码如下:

复制代码 代码如下:
class day{
   function ubb($text) {      /// ubb代码转换
        //$text=htmlspecialchars($text);
        //$text=ereg_replace("\r\n","<br>",$text);
        $text=ereg_replace("\[br\]","<br />",$text);
        $text=nl2br($text);
        $text=stripslashes($text);
        $text=preg_replace("/\\t/is"," ",$text);
        $text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\"\\1\" target=\"new\"><u>\\1</u></a>",$text);
        $text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"http://\\1\" target=\"new\"><u>\\1</u></a>",$text);
        $text=preg_replace("/\[url=(http:\/\/.+?)\](.+?)\[\/url\]/is","<a href=\"\\1\" target=\"new\"><u>\\2</u></a>",$text);
        $text=preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is","<a href=\"http://\\1\" target=\"new\"><u>\\2</u></a>",$text);
        $text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\"\\1\">\\2</font>",$text);
        $text=preg_replace("/\[font=(.+?)\](.+?)\[\/font\]/is","<font face=\"\\1\">\\2</font>",$text);
        $text=preg_replace("/\[email=(.+?)\](.+?)\[\/email\]/is","<a href=\"mailto:\\1\"><u>\\2</u></a>",$text);
        $text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href=\"mailto:\\1\"><u>\\1</u></a>",$text);
        $text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$text);
        $text=preg_replace("/\[u\](.+?)\[\/u\]/is","<u>\\1</u>",$text);
        $text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$text);
        $text=preg_replace("/\[fly\](.+?)\[\/fly\]/is","<marquee width=\"98%\" behavior=\"alternate\" scrollamount=\"3\">\\1</marquee>",$text);
        $text=preg_replace("/\[move\](.+?)\[\/move\]/is","<marquee width=\"98%\" scrollamount=\"3\">\\1</marquee>",$text);
        $text=preg_replace("/\[shadow=([#0-9a-z]{1,10})\,([0-9]{1,3})\,([0-9]{1,2})\](.+?)\[\/shadow\]/is","<table width=\"*\"><tr><td style=\"filter:shadow(color=\\1, direction=\\2 ,strength=\\3)\">\\4</td></tr></table>",$text);
        return $text;
  }
}

希望本文所述对大家的php程序设计有所帮助。