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原理之Session Gc的一个小概率Notice
Apr 12 PHP
php 转换字符串编码 iconv与mb_convert_encoding的区别说明
Nov 10 PHP
php开发留言板的CRUD(增,删,改,查)操作
Apr 19 PHP
PHP rawurlencode与urlencode函数的深入分析
Jun 08 PHP
php利用cookie实现自动登录的方法
Dec 10 PHP
避免Smarty与CSS语法冲突的方法
Mar 02 PHP
使用php从身份证号中获取一系列线索(星座、生肖、生日等)
May 11 PHP
使用PHPExcel实现数据批量导出为excel表格的方法(必看)
Jun 09 PHP
PHP实现基于图的深度优先遍历输出1,2,3...n的全排列功能
Nov 10 PHP
Laravel 登录后清空COOKIE的操作方法
Oct 14 PHP
php 使用html5 XHR2实现上传文件与进度显示功能示例
Mar 03 PHP
TP5框架安全机制实例分析
Apr 05 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
PHP4 与 MySQL 数据库操作函数详解
2006/12/06 PHP
Discuz 模板引擎的封装类代码
2008/07/18 PHP
php array_walk() 数组函数
2011/07/12 PHP
PHP中返回引用类型的方法
2015/04/03 PHP
解析WordPress中控制用户登陆和判断用户登陆的PHP函数
2016/03/01 PHP
PHP入门教程之PHP操作MySQL的方法分析
2016/09/11 PHP
php 字符串中是否包含指定字符串的多种方法
2018/04/12 PHP
php设计模式之状态模式实例分析【星际争霸游戏案例】
2020/03/26 PHP
如何在PHP中读写文件
2020/09/07 PHP
javascript 对表格的行和列都能加亮显示
2008/12/26 Javascript
JS+CSS实现一个气泡提示框
2013/08/18 Javascript
jquery选择器、属性设置用法经验总结
2013/09/08 Javascript
Javascript之this关键字深入解析
2013/11/12 Javascript
js用typeof方法判断undefined类型
2014/07/15 Javascript
easyUI实现类似搜索框关键词自动提示功能示例代码
2016/12/27 Javascript
nodejs 实现钉钉ISV接入的加密解密方法
2017/01/16 NodeJs
js 性能优化之快速响应的用户界面
2017/02/15 Javascript
vue webpack打包后图片路径错误的完美解决方法
2018/12/07 Javascript
express 项目分层实践详解
2018/12/10 Javascript
原生js实现Flappy Bird小游戏
2018/12/24 Javascript
详解JavaScript的数据类型以及数据类型的转换
2019/04/20 Javascript
JS开发自己的类库实例分析
2019/08/28 Javascript
从零学Python之入门(五)缩进和选择
2014/05/27 Python
python使用in操作符时元组和数组的区别分析
2015/05/19 Python
tensorflow 用矩阵运算替换for循环 用tf.tile而不写for的方法
2018/07/27 Python
Django高级编程之自定义Field实现多语言
2019/07/02 Python
Python+OpenCV实现将图像转换为二进制格式
2020/01/09 Python
详解pycharm配置python解释器的问题
2020/10/15 Python
带有css3动画效果的兼容多浏览器简单导航条示例
2014/01/26 HTML / CSS
HTML5 script元素async、defer异步加载使用介绍
2013/08/23 HTML / CSS
Can a struct inherit from another class? (结构体能继承类吗)
2014/07/22 面试题
常用UNIX 命令(Linux的常用命令)
2013/07/10 面试题
银行类自荐信
2014/02/04 职场文书
售后服务承诺书怎么写
2014/05/21 职场文书
pytorch Dropout过拟合的操作
2021/05/27 Python
DIY胆机必读:各国电子管评价
2022/04/06 无线电