php UBB 解析实现代码


Posted in PHP onNovember 27, 2011
/** 
+---------------------------------------------------------- 
* UBB 解析 
+---------------------------------------------------------- 
* @return string 
+---------------------------------------------------------- 
*/ 
function ubb($Text) { 
$Text=trim($Text); 
$Text=ereg_replace("\n","<br>",$Text); 
$Text=preg_replace("/\\t/is"," ",$Text); 
$Text=preg_replace("/\[hr\]/is","<hr>",$Text); 
$Text=preg_replace("/\[separator\]/is","<br/>",$Text); 
$Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text); 
$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text); 
$Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text); 
$Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text); 
$Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text); 
$Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text); 
$Text=preg_replace("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$Text); 
//$Text=preg_replace("/\[url=([^\[]*)\](.+?)\[\/url\]/is","<a href=\\1 target='_blank'>\\2</a>",$Text); 
$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\"\\1\" target='_blank'>\\1</a>",$Text); 
$Text=preg_replace("/\[url=(http:\/\/.+?)\](.+?)\[\/url\]/is","<a href='\\1' target='_blank'>\\2</a>",$Text); 
$Text=preg_replace("/\[url=(.+?)\](.+?)\[\/url\]/is","<a href=\\1>\\2</a>",$Text); 
$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1>",$Text); 
$Text=preg_replace("/\[img\s(.+?)\](.+?)\[\/img\]/is","<img \\1 src=\\2>",$Text); 
$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text); 
$Text=preg_replace("/\[colorTxt\](.+?)\[\/colorTxt\]/eis","color_txt('\\1')",$Text); 
$Text=preg_replace("/\[style=(.+?)\](.+?)\[\/style\]/is","<div class='\\1'>\\2</div>",$Text); 
$Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text); 
$Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text); 
$Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text); 
$Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text); 
$Text=preg_replace("/\[emot\](.+?)\[\/emot\]/eis","emot('\\1')",$Text); 
$Text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href='mailto:\\1'>\\1</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("/\[quote\](.+?)\[\/quote\]/is","<blockquote>引用:<div style='border:1px solid silver;background:#EFFFDF;color:#393939;padding:5px' >\\1</div></blockquote>", $Text); 
$Text=preg_replace("/\[code\](.+?)\[\/code\]/eis","highlight_code('\\1')", $Text); 
$Text=preg_replace("/\[php\](.+?)\[\/php\]/eis","highlight_code('\\1')", $Text); 
$Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align: left; color: darkgreen; margin-left: 5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>", $Text); 
return $Text; 
}
PHP 相关文章推荐
php函数的常用方法及注意之处小结
Jul 10 PHP
php实现单链表的实例代码
Mar 22 PHP
php实现斐波那契数列的简单写法
Jul 19 PHP
对PHP新手的一些建议(PHP学习经验总结)
Aug 20 PHP
PHP函数实现分页含文本分页和数字分页
Oct 23 PHP
PHP使用DirectoryIterator显示下拉文件列表的方法
Mar 13 PHP
php编译安装php-amq扩展简明教程
Jun 25 PHP
php mysql实现mysql_select_db选择数据库
Dec 30 PHP
PHP生成图片验证码功能示例
Jan 12 PHP
浅谈PHP实现大流量下抢购方案
Dec 15 PHP
yii2.0框架场景的简单使用示例
Jan 25 PHP
php 使用ActiveMQ发送消息,与处理消息操作示例
Feb 23 PHP
PHP高自定义性安全验证码代码
Nov 27 #PHP
php中XMLHttpRequest(Ajax)不能设置自定义的Referer的解决方法
Nov 26 #PHP
Linux fgetcsv取得的数组元素为空字符串的解决方法
Nov 25 #PHP
php 团购折扣计算公式
Nov 24 #PHP
php中$_REQUEST、$_POST、$_GET的区别和联系小结
Nov 23 #PHP
打造超酷的PHP数据饼图效果实现代码
Nov 23 #PHP
DISCUZ在win2003环境下 Unable to access ./include/common.inc.php in... 的问题终极解决方案
Nov 21 #PHP
You might like
PHP Zip解压 文件在线解压缩的函数代码
2010/05/26 PHP
php eval函数用法 PHP中eval()函数小技巧
2012/10/31 PHP
解析mysql left( right ) join使用on与where筛选的差异
2013/06/18 PHP
php解析html类库simple_html_dom(详细介绍)
2013/07/05 PHP
免费的ip数据库淘宝IP地址库简介和PHP调用实例
2014/04/08 PHP
php gd等比例缩放压缩图片函数
2016/06/12 PHP
Linux平台php命令行程序处理管道数据的方法
2016/11/10 PHP
php 从一个数组中随机的取出若干个不同的数实例
2016/12/31 PHP
24款非常有用的 jQuery 插件分享
2011/04/06 Javascript
JQuery文字列表向上滚动的代码
2013/11/13 Javascript
jquery序列化表单以及回调函数的使用示例
2014/07/02 Javascript
JavaScript 基本概念
2015/01/20 Javascript
JQuery中clone方法复制节点
2015/05/18 Javascript
jQuery UI设置固定日期选择特效代码分享
2015/08/27 Javascript
AngularJS入门(用ng-repeat指令实现循环输出
2016/05/05 Javascript
在Web项目中引入Jquery插件报错的完美解决方案(图解)
2016/09/19 Javascript
jQuery中hover方法搭配css的hover选择器,实现选中元素突出显示方法
2017/05/08 jQuery
EasyUI框架 使用Ajax提交注册信息的实现代码
2017/09/27 Javascript
微信小程序富文本渲染引擎的详解
2017/09/30 Javascript
NodeJS爬虫实例之糗事百科
2017/12/14 NodeJs
VUE渲染后端返回含有script标签的html字符串示例
2019/10/28 Javascript
node中短信api实现验证码登录的示例代码
2021/01/20 Javascript
python 装饰器功能以及函数参数使用介绍
2012/01/27 Python
python实现udp数据报传输的方法
2014/09/26 Python
wxPython事件驱动实例详解
2014/09/28 Python
Java Web开发过程中登陆模块的验证码的实现方式总结
2016/05/25 Python
Python面向对象编程基础解析(一)
2017/10/26 Python
python机器学习之贝叶斯分类
2018/03/26 Python
Python global全局变量函数详解
2018/09/18 Python
对pandas数据判断是否为NaN值的方法详解
2018/11/06 Python
Python 炫技操作之合并字典的七种方法
2020/04/10 Python
python 用struct模块解决黏包问题
2020/11/07 Python
windows系统Tensorflow2.x简单安装记录(图文)
2021/01/18 Python
韩国CJ食品专卖网:CJonmart
2016/09/11 全球购物
英国羊皮鞋类领先品牌:Just Sheepskin
2019/12/12 全球购物
详解Spring Security如何在权限中使用通配符
2022/06/28 Java/Android