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 相关文章推荐
BBS(php &amp; mysql)完整版(二)
Oct 09 PHP
PHPMailer邮件类利用smtp.163.com发送邮件方法
Sep 11 PHP
mysqli_set_charset和SET NAMES使用抉择及优劣分析
Jan 13 PHP
使用PHP遍历文件目录与清除目录中文件的实现详解
Jun 24 PHP
destoon实现调用图文新闻的方法
Aug 21 PHP
php使用ereg验证文件上传的方法
Dec 16 PHP
php实现的简单日志写入函数
Mar 31 PHP
php实现zip文件解压操作
Nov 03 PHP
ThinkPHP中session函数详解
Sep 14 PHP
Yii2.0使用阿里云OSS的SDK上传图片、下载、删除图片示例
Sep 20 PHP
php实现微信企业转账功能
Oct 02 PHP
详解PHP服务器如何在有限的资源里最大提升并发能力
May 25 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的cURL快速入门教程 (小偷采集程序)
2011/06/02 PHP
php addslashes 利用递归实现使用反斜线引用字符串
2013/08/05 PHP
php注册审核重点解析(数据访问)
2017/05/23 PHP
用js计算页面执行时间的函数
2006/12/07 Javascript
javascript学习笔记(七)利用javascript来创建和存储cookie
2011/04/08 Javascript
关于ExtJS4.1:快捷键支持的问题
2013/04/24 Javascript
利用Keydown事件阻止用户输入实现代码
2014/03/11 Javascript
jquery搜索框效果实现方法
2015/01/16 Javascript
Node.js返回JSONP详解
2016/05/18 Javascript
深入理解Angular中的依赖注入
2017/06/26 Javascript
jQuery实现checkbox即点即改批量删除及中间遇到的坑
2017/11/11 jQuery
element-ui 限制日期选择的方法(datepicker)
2018/05/16 Javascript
js实现轮播图效果 z-index实现轮播图
2020/01/17 Javascript
javascript实现前端成语点击验证优化
2020/06/24 Javascript
浅析vue中的nextTick
2020/12/28 Vue.js
python使用BeautifulSoup分析网页信息的方法
2015/04/04 Python
在RedHat系Linux上部署Python的Celery框架的教程
2015/04/07 Python
python正则表达式之作业计算器
2016/03/18 Python
Python中列表与元组的乘法操作示例
2018/02/10 Python
Python 编码规范(Google Python Style Guide)
2018/05/05 Python
Python3实现爬虫爬取赶集网列表功能【基于request和BeautifulSoup模块】
2018/12/05 Python
解决python3.5 正常安装 却不能直接使用Tkinter包的问题
2019/02/22 Python
django多对多表的创建,级联删除及手动创建第三张表
2019/07/25 Python
python创建学生成绩管理系统
2019/11/22 Python
利用Python将多张图片合成视频的实现
2020/11/23 Python
简单掌握CSS3将文字描边及填充文字颜色的方法
2016/03/07 HTML / CSS
html5应用缓存_动力节点Java学院整理
2017/07/13 HTML / CSS
澳大利亚排名第一的狂热牛仔品牌:ONETEASPOON
2018/11/20 全球购物
美容院营销方案
2014/03/05 职场文书
幼儿教师师德承诺书
2014/05/23 职场文书
2015年度班主任自我评价
2015/03/11 职场文书
学术研讨会主持词
2015/07/04 职场文书
公司备用金管理制度
2015/08/04 职场文书
2016年过年放假安排通知
2015/08/18 职场文书
市级三好生竞选稿
2015/11/21 职场文书
浅谈MySQL之select优化方案
2021/08/07 MySQL