php过滤UBB代码类的解决办法
内容摘要
这篇文章主要为大家详细介绍了php过滤UBB代码类的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
本文实例讲述了php实
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
本文实例讲述了php实
文章正文
这篇文章主要为大家详细介绍了php过滤UBB代码类的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随php教程的小玲来看看吧!
本文实例讲述了php实现过滤UBB代码的类。分享给大家供大家参考。具体如下:
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <code class = "language-php" > // php教程 www.idcnote.com 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 ; } }</code> |
注:关于php过滤UBB代码类的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释