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中substr()与explode()函数用法分析

本文实例讲述了PHP中substr()与explode()函数用法。分享给大家供大家参考。具体方法如下: substr(string,start,length):本函数将字符串 stri...

php求圆周率的简单实现方法 原创

本文实例讲述了php求圆周率的简单实现方法。分享给大家供大家参考,具体如下: 前面一篇《C语言求圆周率》给出了一个圆周率的简单计算方法,这里借鉴前面的代码给出php求圆周率的运算方法。具...

PHP单元测试利器 PHPUNIT初探第1/2页

PHP单元测试利器 PHPUNIT初探第1/2页

当你遇到以上这些令你沮丧的情况时,你一定会想能有什么更好的办法去解决呢?办法当然是有的!这就是使用单元测试。单元测试不但可以在一定程度上解决上述头疼的问题,而且能让代码变的容易维护,还可...

php文件后缀不强制为.php的实操方法

php文件后缀不强制为.php的实操方法

在大家学习PHP中,认为php文件的后缀一定为.php,其实不然,我们可以把它写成其他的后缀。这样也可以防止其他人的恶意攻击。 php文件后缀不强制为.php 首先,我们先测试一下,P...

神盾加密解密教程(一)PHP变量可用字符

先来说说php变量的命名规则,百度下一抓一大把:(1) PHP的变量名区分大小写;(2) 变量名必须以美元符号$开始;(3) 变量名开头可以以下划线开始;(4) 变量名不能以数字字符开头...