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 相关文章推荐
实战mysql导出中文乱码及phpmyadmin导入中文乱码的解决方法
Jun 11 PHP
php运行出现Call to undefined function curl_init()的解决方法
Nov 02 PHP
一些PHP Coding Tips(php小技巧)[2011/04/02最后更新]
May 02 PHP
php全排列递归算法代码
Oct 09 PHP
php文件服务实现虚拟挂载其他目录示例
Apr 17 PHP
PHP使用feof()函数读文件的方法
Nov 07 PHP
PHP字符串比较函数strcmp()和strcasecmp()使用总结
Nov 19 PHP
php控制文件下载速度的方法
Mar 24 PHP
为你总结一些php信息函数
Oct 21 PHP
详解YII关联查询
Jan 10 PHP
PHP支付系统设计与典型案例分享
Aug 02 PHP
PHP实现按之字形顺序打印二叉树的方法
Jan 16 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
自己动手,丰衣足食 - 短波框形天线制作
2021/03/01 无线电
PHP详细彻底学习Smarty
2008/03/27 PHP
通俗易懂的php防注入代码
2010/04/07 PHP
PHP写的求多项式导数的函数代码
2012/07/04 PHP
destoon实现调用图文新闻的方法
2014/08/21 PHP
PHP动态生成指定大小随机图片的方法
2016/03/25 PHP
PHP7+Nginx的配置与安装教程详解
2016/05/10 PHP
用jscript实现新建word文档
2007/06/15 Javascript
表单填写时用回车代替TAB的实现方法
2007/10/09 Javascript
Node.js实战 建立简单的Web服务器
2012/03/08 Javascript
jquery图片放大镜功能的实例代码
2013/03/26 Javascript
JS中的prototype与面向对象的实例讲解
2013/05/22 Javascript
zeroclipboard 单个复制按钮和多个复制按钮的实现方法
2014/06/14 Javascript
JavaScript基础篇(6)之函数表达式闭包
2015/12/11 Javascript
JS实现保留n位小数的四舍五入问题示例
2016/08/03 Javascript
jquery.validate[.unobtrusive]和Bootstrap实现tooltip错误提示问题分析
2016/10/30 Javascript
js实现产品缩略图效果
2017/03/10 Javascript
socket.io学习教程之基础介绍(一)
2017/04/29 Javascript
在vue中使用vue-echarts-v3的实例代码
2018/09/13 Javascript
uni-app微信小程序登录授权的实现
2020/05/22 Javascript
浅谈pandas中shift和diff函数关系
2018/04/08 Python
Python多线程应用于自动化测试操作示例
2018/12/06 Python
python 去除二维数组/二维列表中的重复行方法
2019/01/23 Python
python opencv将表格图片按照表格框线分割和识别
2019/10/30 Python
python 创建一维的0向量实例
2019/12/02 Python
Python使用xpath实现图片爬取
2020/09/16 Python
浅谈three.js中的needsUpdate的应用
2012/11/12 HTML / CSS
使用phonegap操作数据库的实现方法
2017/03/31 HTML / CSS
Fashion Eyewear美国:英国线上设计师眼镜和太阳镜的零售商
2016/08/15 全球购物
New Balance澳大利亚官网:运动鞋和健身服装
2019/02/23 全球购物
晚宴邀请函范文
2014/01/15 职场文书
文秘大学生求职信
2014/02/25 职场文书
2015年卫生局工作总结
2015/07/24 职场文书
班主任工作经验交流会总结
2015/11/02 职场文书
《巫师》是美食游戏?CDPR10月将推出《巫师》官方食谱
2022/04/03 其他游戏
使用pd.merge表连接出现多余行的问题解决
2022/06/16 Python