php实现转换ubb代码的方法

yipeiwu_com5年前PHP代码库

本文实例讲述了php实现转换ubb代码的方法。分享给大家供大家参考。具体如下:

function ubb2html($content)
{
global $article;
//是否自动识别
if ($article['isparseurl'] == "1")
{
$content = parseurl($content);
}
//自动识别结束
$content = eregi_replace(quotemeta("[b]"),quotemeta("<b>"),$content);
$content = eregi_replace(quotemeta("[/b]"),quotemeta("</b>"),$content);
$content = eregi_replace(quotemeta("[i]"),quotemeta("<i>"),$content);
$content = eregi_replace(quotemeta("[/i]"),quotemeta("</i>"),$content);
$content = eregi_replace(quotemeta("[u]"),quotemeta("<u>"),$content);
$content = eregi_replace(quotemeta("[/u]"),quotemeta("</u>"),$content);
$content = eregi_replace(quotemeta("[center]"),quotemeta("<center>"),$content);
$content = eregi_replace(quotemeta("[/center]"),quotemeta("</center>"),$content);
$content = eregi_replace(quotemeta("[quote]"),quotemeta("<table width=\"96%\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\" style=word-break:break-all align=\"center\"><tr><td><b>引用:</b></td></tr><tr><td><hr width=\"100%\" noshade></td></tr><tr><td class=\"content\"><font color=\"#0000FF\">"),$content);
$content = eregi_replace(quotemeta("[/quote]"),quotemeta("</font></td></tr><tr><td><hr width=\"100%\" noshade></td></tr></table>"),$content);
$content = eregi_replace(quotemeta("
复制代码 代码如下:
"),quotemeta("<table width=\"96%\" border=\"0\" cellspacing=\"3\" cellpadding=\"0\" style=word-break:break-all align=\"center\"><tr><td><b>代码:</b></td></tr><tr><td><hr width=\"100%\" noshade></td></tr><tr><td class=\"code\"><font color=\"#0000FF\">"),$content); $content = eregi_replace(quotemeta("
"),quotemeta("</font></td></tr><tr><td><hr width=\"100%\" noshade></td></tr></table>"),$content); $content = eregi_replace("\\[images\\]([^\\[]*)\\[/images\\]","<a href=\"\\1\" target=\"_blank\"><img src=\"\\1\" border=0 onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\" title=\"用新窗口浏览原始图片\"></a>",$content); $content = eregi_replace("\\[url\\]www.([^\\[]*)\\[/url\\]", "<a href=\"http://www.\\1\" target=_blank>www.\\1</a>",$content); $content = eregi_replace("\\[url\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\1</a>",$content); $content = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$content); $content = eregi_replace("\\[email\\]([^\\[]*)\\[/email\\]", "<a href=\"mailto:\\1\">\\1</a>",$content); //$content = preg_replace( '/javascript/i', 'java script', $content); return $content; }

希望本文所述对大家的php程序设计有所帮助。

相关文章

php实现的Cookies操作类实例

本文实例讲述了PHP实现的Cookies操作类及其用法,分享给大家供大家参考。具体分析如下: 一、功能: 1.保存,读取,更新,清除cookies数据。 2.可设置前缀。 3.强制超时控...

php实现多维数组中每个单元值(数字)翻倍的方法

本文实例讲述了php实现多维数组中每个单元值(数字)翻倍的方法。分享给大家供大家参考。具体分析如下: 前提:一个多维数组,它的每个最小单元值都为数字。 要求:写一个函数,将最小单元值翻倍...

PHP中用接口、抽象类、普通基类实现“面向接口编程”与“耦合方法”简述

复制代码 代码如下: <?php /* 边学边做的,为方便自己翻阅而发布,更为得到高人指点而发布,欢迎高手指点...... 【提示】本例通过测试无误 【情景设计】 模拟计算机主板I...

PHP Ajax实现页面无刷新发表评论

大家都有在网站发表评论的经历,传统的发表过程无非是:发表->提交页面表单->等待刷新页面,这样在网络比较拥挤的时候,往往需要漫长的等待,今天介绍用PHP+Ajax实现页面无刷...

10个值得深思的PHP面试题

10个值得深思的PHP面试题

文章所罗列的问题虽然看似简单,但是每个背后都涵盖了一个或几个大家容易忽视的基础知识点,希望能够帮助到你的面试和平时工作。 Q1 第一个问题关于弱类型 $str1 = 'yabadab...