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&amp;&amp;mysql)二
Oct 09 PHP
用PHP获取Google AJAX Search API 数据的代码
Mar 12 PHP
PHP获取文件相对路径的方法
Feb 26 PHP
php 把数字转换成汉字的代码
Jul 21 PHP
PHP crc32()函数讲解
Feb 14 PHP
PHP中ltrim()函数的用法与实例讲解
Mar 28 PHP
详解提高使用Java反射的效率方法
Apr 29 PHP
TP5(thinkPHP框架)实现后台清除缓存功能示例
May 29 PHP
PHP使用PDO创建MySQL数据库、表及插入多条数据操作示例
May 30 PHP
php设计模式之单例模式用法经典示例分析
Sep 20 PHP
PHP实现爬虫爬取图片代码实例
Mar 03 PHP
PHP引擎php.ini参数优化深入讲解
Mar 24 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
Thinkphp中的curd应用实用要点
2015/01/04 PHP
YII2框架中excel表格导出的方法详解
2017/07/21 PHP
PHP ADODB实现分页功能简单示例
2018/05/25 PHP
PHP+iframe模拟Ajax上传文件功能示例
2019/07/02 PHP
JavaScript监测ActiveX控件是否已经安装过的代码
2008/09/02 Javascript
jquery中append()与appendto()用法分析
2014/11/14 Javascript
JS实现自动定时切换的简洁网页选项卡效果
2015/10/13 Javascript
常用的javascript设计模式
2017/01/11 Javascript
jQuery插件FusionCharts实现的MSBar2D图效果示例【附demo源码】
2017/03/24 jQuery
bootstrap fileinput实现文件上传功能
2017/08/23 Javascript
Node做中转服务器转发接口
2017/10/18 Javascript
vue使用$emit时,父组件无法监听到子组件的事件实例
2018/02/26 Javascript
详解vue-cli 构建项目 vue-cli请求后台接口 vue-cli使用axios、sass、swiper
2018/05/28 Javascript
浅析前端路由简介以及vue-router实现原理
2018/06/01 Javascript
Vue中Table组件Select的勾选和取消勾选事件详解
2019/03/19 Javascript
详解Js里的for…in和for…of的用法
2019/03/28 Javascript
Vue路由权限控制解析
2020/11/09 Javascript
jQuery实现手风琴特效
2021/01/11 jQuery
python编码总结(编码类型、格式、转码)
2016/07/01 Python
Python编程实现删除VC临时文件及Debug目录的方法
2017/03/22 Python
pyqt5简介及安装方法介绍
2018/01/31 Python
numpy添加新的维度:newaxis的方法
2018/08/02 Python
python连接mongodb密码认证实例
2018/10/16 Python
PyTorch的深度学习入门之PyTorch安装和配置
2019/06/27 Python
详解Python中list[::-1]的几种用法
2020/11/16 Python
印尼穆斯林时尚购物网站:Hijabenka
2016/12/10 全球购物
精油和天然健康美容产品:Art Naturals
2018/01/27 全球购物
十一个高级MySql面试题
2014/10/06 面试题
医学专业个人求职自荐信格式
2013/09/23 职场文书
工程部主管岗位职责
2013/11/17 职场文书
网上签名寄语活动留言
2014/01/18 职场文书
军训鉴定表自我鉴定
2014/02/13 职场文书
一篇合格的广告文案,其主要目的是什么?
2019/07/12 职场文书
Golang使用Panic与Recover进行错误捕获
2022/03/22 Golang
【D4DJ】美少女DJ企划 动画将于明年冬季开播第2季
2022/04/11 日漫
Python3使用Qt5来实现简易的五子棋小游戏
2022/05/02 Python