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程序设计有所帮助。

相关文章

解决wincache不支持64位PHP5.5/5.6的问题(提供64位wincache下载) 原创

解决wincache不支持64位PHP5.5/5.6的问题(提供64位wincache下载) 原创

这几天公司有台服务器需要配置,系统是Windows 2008 R2,在IIS上配置环境是64位的PHP5.5,要求支持wincache。原本心想无非就是去wincache的官网下载下来,...

PHP实现的简单异常处理类示例

本文实例讲述了PHP实现的简单异常处理类。分享给大家供大家参考,具体如下: <?php header('content-type:text/html;charset=U...

PHP中cookies使用指南

综述    Cookie是在HTTP协议下,服务器或脚本可以维护客户工作站上信息的一种方式。Cookie是由Web服务器保存在用户浏览器上的小文件,它可以包含有关用户的信息(如...

dirname(__FILE__)的含义和应用说明

__FILE__表示当前所在文件的绝对路径包括文件名,dirname(__FILE__)表示当前文件的绝对路径,basename(__FILE__)表示当前文件的文件名称,dirname...

PHP排序算法系列之直接选择排序详解

直接选择排序 直接选择排序(Straight Select Sorting) 的基本思想是:第一次从R[0]~R[n-1]中选取最小值,与R[0]交换,第二次从R[1]~R[n-1]中选...