目录
PHP写的UBB代码转换函数 ubb转html
Jun 06, 2016 pm 07:32 PM
html
php
代码
函数
有
转换
有时需要用到ubb转html,比如说在留言的时候,所以就搞了这个,希望对朋友们有用。 无 ?phpfunction ubb($Text) {$Text=trim($Text);$Text=ereg_replace("\n","br",$Text);$Text=preg_replace("/\\t/is"," ",$Text);$Text=preg_replace("/\[hr\]/is","hr",$Te
有时需要用到ubb转html,比如说在留言的时候,所以就搞了这个,希望对朋友们有用。
<?php 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 id="">\\1</h1>",$Text); $Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2 id="">\\1</h2>",$Text); $Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3 id="">\\1</h3>",$Text); $Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4 id="">\\1</h4>",$Text); $Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5 id="">\\1</h5>",$Text); $Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6 id="">\\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 alt="PHP写的UBB代码转换函数 ubb转html" >",$Text); $Text=preg_replace("/\[img\s(.+?)\](.+?)\[\/img\]/is","<img \\1 src=\\2 alt="PHP写的UBB代码转换函数 ubb转html" >",$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 class="brush:php;toolbar:false">\\1
登录后复制
引用:", $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","\\1
--------------------------
\\1
--------------------------
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

适用于 Ubuntu 和 Debian 的 PHP 8.4 安装和升级指南
