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 相关文章推荐
用 PHP5 轻松解析 XML
Dec 04 PHP
require(),include(),require_once()和include_once()的异同
Jan 02 PHP
发款php蜘蛛统计插件只要有mysql就可用
Oct 12 PHP
PHP最常用的2种设计模式工厂模式和单例模式介绍
Aug 14 PHP
php可应用于面包屑导航的迭代寻找家谱树实现方法
Feb 02 PHP
PHP树的深度编历生成迷宫及A*自动寻路算法实例分析
Mar 10 PHP
ThinkPHP路由详解
Jul 27 PHP
织梦sitemap地图实时推送给百度的教程
Aug 03 PHP
盘点PHP和ASP.NET的10大对比!
Dec 24 PHP
PHP简单判断手机设备的方法
Aug 23 PHP
详解PHP处理密码的几种方式
Nov 30 PHP
PHP实现超简单的SSL加密解密、验证及签名的方法示例
Aug 28 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 header下载函数
2014/01/31 PHP
PHP开源开发框架ZendFramework使用中常见问题说明及解决方案
2014/06/12 PHP
PHP实现简单数字分页效果
2015/07/26 PHP
CI框架的安全性分析
2016/05/18 PHP
跨浏览器开发经验总结(三)   警惕“IE依赖综合症”
2010/05/13 Javascript
cookie的复制与使用记住用户名实现代码
2013/11/04 Javascript
jquery使用ul模拟select实现表单美化的方法
2015/08/18 Javascript
JavaScript多并发问题如何处理
2015/10/28 Javascript
全面解析bootstrap格子布局
2016/05/22 Javascript
HTML页面,测试JS对C函数的调用简单实例
2016/08/09 Javascript
jQuery+HTML5实现WebGL高性能烟花绽放动画效果【附demo源码下载】
2017/08/18 jQuery
详解wow.js中各种特效对应的类名
2017/09/13 Javascript
jQuery实现的简单对话框拖动功能示例
2018/06/05 jQuery
Vue-CLI 项目在pycharm中配置方法
2019/08/30 Javascript
Vue父子组件传值的一些坑
2020/09/16 Javascript
通过mod_python配置运行在Apache上的Django框架
2015/07/22 Python
Python利用BeautifulSoup解析Html的方法示例
2017/07/30 Python
Python格式化输出字符串方法小结【%与format】
2018/10/29 Python
Python从Excel中读取日期一列的方法
2018/11/28 Python
pandas计算最大连续间隔的方法
2019/07/04 Python
Python使用QQ邮箱发送邮件报错smtplib.SMTPAuthenticationError
2019/12/20 Python
带你彻底搞懂python操作mysql数据库(cursor游标讲解)
2020/01/06 Python
Python属性和内建属性实例解析
2020/01/14 Python
Python +Selenium解决图片验证码登录或注册问题(推荐)
2020/02/09 Python
Pandas的数据过滤实现
2021/01/15 Python
美国奢侈品购物平台:Orchard Mile
2018/05/02 全球购物
10条PHP编程习惯
2014/05/26 面试题
企业给企业的表扬信
2014/01/13 职场文书
大学毕业自我评价
2014/02/02 职场文书
汽车维修工岗位职责
2014/02/12 职场文书
《北大荒的秋天》教学反思
2014/04/14 职场文书
大学生入党推荐书范文
2014/05/17 职场文书
上班迟到检讨书
2014/09/15 职场文书
2015年小学语文教学工作总结
2015/05/25 职场文书
Python连续赋值需要注意的一些问题
2021/06/03 Python
python中pd.cut()与pd.qcut()的对比及示例
2022/06/16 Python