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 相关文章推荐
WINDOWS服务器安装多套PHP的另类解决方案
Oct 09 PHP
社区(php&amp;&amp;mysql)二
Oct 09 PHP
ThinkPHP查询语句与关联查询用法实例
Nov 01 PHP
php实现utf-8转unicode函数分享
Jan 06 PHP
php实现的RSS生成类实例
Apr 23 PHP
PHP连接Nginx服务器并解析Nginx日志的方法
Aug 16 PHP
CI框架源码解读之URI.php中_fetch_uri_string()函数用法分析
May 18 PHP
Laravel中间件实现原理详解
Oct 09 PHP
PHP使用栈解决约瑟夫环问题算法示例
Aug 27 PHP
bindParam和bindValue的区别以及在Yii2中的使用详解
Mar 12 PHP
PHP+mysql实现的三级联动菜单功能示例
Feb 15 PHP
Yii 框架入口脚本示例分析
May 19 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
支持生僻字且自动识别utf-8编码的php汉字转拼音类
2014/06/27 PHP
PHP 使用redis简单示例分享
2015/03/05 PHP
PHP使用in_array函数检查数组中是否存在某个值
2015/03/25 PHP
如何在Mozilla Gecko 用Javascript加载XSL
2007/01/09 Javascript
javascript中的关于类型转换的性能优化
2010/12/14 Javascript
JavaScript高级程序设计(第3版)学习笔记7 js函数(上)
2012/10/11 Javascript
js优化针对IE6.0起作用(详细整理)
2012/12/25 Javascript
Javascript 加载和执行-性能提高篇
2012/12/28 Javascript
判断javascript的数据类型(示例代码)
2013/12/11 Javascript
JS判断网页广告是否被浏览器拦截过滤的代码
2015/04/05 Javascript
AngularJS深入探讨scope,继承结构,事件系统和生命周期
2016/11/02 Javascript
vuejs2.0实现一个简单的分页示例
2017/02/22 Javascript
详解JavaScript中typeof与instanceof用法
2018/10/24 Javascript
Vue js 的生命周期(看了就懂)(推荐)
2019/03/29 Javascript
JS实现的排列组合算法示例
2019/07/16 Javascript
一篇文章弄懂javascript中的执行栈与执行上下文
2019/08/09 Javascript
js实现指定时间倒计时效果
2019/08/26 Javascript
Node.js利用Express实现用户注册登陆功能(推荐)
2020/10/26 Javascript
python随机生成指定长度密码的方法
2015/04/04 Python
在Django的通用视图中处理Context的方法
2015/07/21 Python
python 实时遍历日志文件
2016/04/12 Python
python Selenium爬取内容并存储至MySQL数据库的实现代码
2017/03/16 Python
使用Selenium破解新浪微博的四宫格验证码
2018/10/19 Python
Python如何使用paramiko模块连接linux
2020/03/18 Python
超全Python图像处理讲解(多模块实现)
2020/04/13 Python
Django静态文件加载失败解决方案
2020/08/26 Python
Django nginx配置实现过程详解
2020/09/10 Python
俄罗斯购买剧院和演唱会门票网站:Parter.ru
2019/11/09 全球购物
自我评价格式
2014/01/06 职场文书
自主招生推荐信范文
2014/05/10 职场文书
财务管理专业求职信
2014/06/11 职场文书
2015年社区卫生工作总结
2015/04/21 职场文书
2015年七七事变78周年纪念活动方案
2015/05/06 职场文书
python神经网络编程之手写数字识别
2021/05/08 Python
golang语言指针操作
2022/04/14 Golang
解决IDEA翻译插件Translation报错更新TTK失败不能使用
2022/04/24 Python