php的把ubb代码转换成html代码的程序
发布:smiling 来源: PHP粉丝网 添加日期:2013-12-09 15:07:04 浏览: 评论:0
- <?php
- function ubbcode($str){
- //$str = str_replace("file:","file :",$str);
- //$str = str_replace("files:","files :",$str);
- //$str = str_replace("script:","script :",$str);
- //$str = str_replace("js:","js :",$str);
- //图片UBB
- $str = preg_replace("/\[img\](http|https|ftp):\/\/(.[^\[]*)\[\/img\]/i", "<a onfocus=\"this.blur()\" href=\"\${1}://\${2}\" target=new><img src=\"\${1}://\${2}\" border=\"0\" alt=\"按此在新窗口浏览图片\" onload=\"javascript:if(this.width>300)this.width=300\"></a>", $str);
- $str = preg_replace("/\[img=*([0-9]*),*([0-9]*)\](http|https|ftp):\/\/(.[^\[]*)\[\/img\]/i", "<a onfocus=\"this.blur()\" href=\"\${3}://\${4}\" target=new><img src=\"\${3}://\${4}\" border=\"0\" width=\"\${1}\" heigh=\"\${2}\" alt=\"按此在新窗口浏览图片\" onload=\"javascript:if(this.width>300)this.width=300\"></a>", $str);
- $str = preg_replace("/(\[img\])images\/face\/em(.*?)\.gif(\[\/img\])/i", "<img src=\"images/face/em\${2}.gif\" />", $str);
- //链接UBB
- $str = preg_replace("/(\[url\])(.[^\[]*)(\[url\])/i", "<a href=\"\${2}\" target=\"new\">\${1}</a>", $str);
- $str = preg_replace("/\[url=(.[^\[]*)\]/i", "<a href=\"\${1}\" target=\"new\">", $str);
- //邮箱UBB
- $str = preg_replace("/(\[email\])(.*?)(\[\/email\])/i", "<img align=\"absmiddle\" \"src=image/email1.gif\"><a href=\"mailto:\${2}\">\${2}</a>", $str);
- $str = preg_replace("/\[email=(.[^\[]*)\]/i", "<img align=\"absmiddle\" src=\"image/email1.gif\"><a href=\"mailto:\${1}\" target=\"new\">", $str);
- //QQ号码UBB
- $str = preg_replace("/\[qq=([0-9]*)\]([0-9]*)\[\/qq\]/i", "<a target=\"new\" href=\"tencent://message/?uin=\${2}&Site=www.52515.net&Menu=yes\"><img border=\"0\" src=\"http://wpa.qq.com/pa?p=1:\${2}:\${1}\" alt=\"点击这里给我发消息\"></a>", $str);
- //颜色UBB
- $str = preg_replace("/\[color=(.[^\[]*)\]/i", "<font color=\"\${1}\">", $str);
- //文字字体UBB
- $str = preg_replace("/\[font=(.[^\[]*)\]/i", "<font face=\"\${1}\">", $str);
- //文字大小UBB
- $str = preg_replace("/\[size=([0-9]*)\]/i", "<font size=\"\${1}\">", $str);
- $str = preg_replace("/\[size=([0-9]*)pt\]/i", "<font size=\"\${1}\">", $str);
- $str = preg_replace("/\[size=([0-9]*)px\]/i", "<font size=\"\${1}\">", $str);
- //文字对齐方式UBB
- $str = preg_replace("/\[align=(center|left|right)\]/i", "<div align=\"\${1}\">", $str);
- //表格UBB
- //$str = preg_replace("/\[table=(.[^\[]*)\]/i", "<table width=\"\${1}\" border=\"1\" style=\"border-collapse:collapse\">", $str);
- //表格UBB2
- //$str = preg_replace("/\[td=([0-9]*),([0-9]*),([0-9]*)\]/i", "<td colspan=\"\${1}\" rowspan=\"\${2}\" width=\"\${3}\">", $str);
- //字体倾斜
- $str = preg_replace("/\[i\]((.|\n)*?)\[\/i\]/i", "<i>\${1}</i>", $str);
- //FLASH动画UBB
- $str = preg_replace("/(\[flash\])(http:\/\/.[^\[]*(.swf))(\[\/flash\])/i", "<a href=\"\${2}\" target=\"new\"><img src=\"image/swf.gif\" border=\"0\" alt=\"点击开新窗口欣赏该flash动画!\" height=\"16\" width=\"16\">[全屏欣赏]</a><br><center><object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"300\" height=\"200\"><param name=\"movie\" value=\"\${2}\"><param name=\"quality\" value=\"high\"><embed src=\"\${2}\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\">\${2}</embed></object></center>", $str);
- $str = preg_replace("/(\[flash=*([0-9]*),*([0-9]*)\])(http:\/\/.[^\[]*(.swf))(\[\/flash\])/i", "<a href=\"\${4}\" target=\"new\"><img src=\"image/swf.gif\" border=\"0\" alt=\"点击开新窗口欣赏该flash动画!\" height=\"16\" width=\"16\">[全屏欣赏]</a><br><center><object codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"\${2}\" height=\"\${3}\"><param name=\"movie\" value=\"\${4}\"><param name=quality value=high><embed src=\"\${4}\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?p1_prod_version=shockwaveflash\" type=\"application/x-shockwave-flash\" width=\"\${2}\" height=\"\${3}\">\${4}</embed></object></center>", $str);
- //MEDIA PLAY播放UBB
- $str = preg_replace("/\[wmv\](.[^\[]*)\[\/wmv]/i", "<object align=\"middle\" classid=\"clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" class=\"object\" id=\"mediaplayer\" width=\"300\" height=\"200\" ><param name=\"showstatusbar\" value=\"-1\"><param name=\"filename\" value=\"\${1}\"><embed type=\"application/x-oleobject\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701\" flename=\"mp\" src=\"\${1}\" width=\"300\" height=\"200\"></embed></object>", $str);
- $str = preg_replace("/\[wmv=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/wmv]/i", "<object align=\"middle\" classid=\"clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" class=\"object\" id=\"mediaplayer\" width=\"\${1}\" height=\"\${2}\" ><param name=\"showstatusbar\" value=\"-1\"><param name=\"filename\" value=\"\${3}\"><embed type=\"application/x-oleobject\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701\" flename=\"mp\" src=\"\${3}\" width=\"\${1}\" height=\"\${2}\"></embed></object>", $str);
- //REALPLAY 播放UBB
- $str = preg_replace("/\[rm\](.[^\[]*)\[\/rm]/i", "<object classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" class=\"object\" id=\"raocx\" width=\"300\" height=\"200\"><param name=\"src\" value=\"\${1}\"><param name=\"console\" value=\"clip1\"><param name=\"controls\" value=\"imagewindow\"><param name=\"autostart\" value=\"true\"></object><br><object classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" height=\"32\" id=\"video2\" width=\"300\"><param name=\"src\" value=\"\${1}\"><param name=\"autostart\" value=\"-1\"><param name=\"controls\" value=\"controlpanel\"><param name=\"console\" value=\"clip1\"></object>", $str);
- $str = preg_replace("/\[rm=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/rm]/i", "<object classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" class=\"object\" id=\"raocx\" width=\"\${1}\" height=\"\${2}\"><param name=\"src\" value=\"\${3}\"><param name=\"console\" value=\"clip1\"><param name=\"controls\" value=\"imagewindow\"><param name=\"autostart\" value=\"true\"></object><br><object classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" height=\"32\" id=\"video2\" width=\"\${1}\"><param name=\"src\" value=\"\${3}\"><param name=\"autostart\" value=\"-1\"><param name=\"controls\" value=\"controlpanel\"><param name=\"console\" value=\"clip1\"></object>", $str);
- $str = str_replace("\r\n", "<BR/>", $str);
- $str = preg_replace("/\[rm=*([0-9]*),*([0-9]*)\](.[^\[]*)\[\/rm]/i", "<object classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" class=\"object\" id=\"raocx\" width=\"\${1}\" height=\"\${2}\"><param name=\"src\" value=\"\${3}\"><param name=\"console\" value=\"clip1\"><param name=\"controls\" value=\"imagewindow\"><param name=\"autostart\" value=\"true\"></object><br><object classid=\"clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa\" height=\"32\" id=\"video2\" width=\"\${1}\"><param name=\"src\" value=\"\${3}\"><param name=\"autostart\" value=\"-1\"><param name=\"controls\" value=\"controlpanel\"><param name=\"console\" value=\"clip1\"></object>", $str);
- /*
- re.pattern="\[code\]((.|\n)*?)\[\/code\]"
- Set tempcodes=re.Execute($str)
- For i=0 To tempcodes.count-1
- re.pattern="<BR/>"
- tempcode=Replace(tempcodes(i),"<BR/>",vbcrlf)
- $str=replace($str,tempcodes(i),tempcode)
- next
- */
- $searcharray = array("[/url]","[/email]","[/color]", "[/size]", "[/font]", "[/align]", "[b]", "[/b]","[u]", "[/u]", "[list]", "[list=1]", "[list=a]","[list=A]", "[*]", "[/list]", "[indent]", "[/indent]","[ DISCUZ_CODE_0 ]","[quote]","[/quote]","[tr]","[td]","[/td]","[/tr]","[/table]");
- $replacearray= array("</a>","</a>","</font>", "</font>", "</font>", "</div>", "<b>", "</b>","<u>", "</u>", "<ul>", "<ol type=1>", "<ol type=a>","<ol type=A>", "<li>", "</ul></ol>", "<blockquote>", "</blockquote>","<div><textarea name=\"codes\" id=\"codes\" rows=\"12\" cols=\"65\">","</textarea><br/><input type=\"button\" value=\"运行代码\" onclick=\"RunCode()\"> <input type=\"button\" value=\"复制代码\" onclick=\"CopyCode()\"> <input type=\"button\" value=\"另存代码\" onclick=\"SaveCode()\"> <input type=\"button\" value=\"跳 转\" onclick=\"Goto(prompt('请输入要跳转到第几行?','1'))\" accesskey=\"g\"> 提示:您可以先修改部分代码再运行</div>","<div style=\"background:#E2F2FF;width:90%;height:auto;border:1px solid #3CAAEC;padding:5px;\">","</div>","<tr>","<td>","</td>","</tr>","</table>");
- for ($i=0; $i<count($searcharray); $i++){
- $str = str_replace($searcharray[$i], $replacearray[$i], $str);
- }
- return $str;
- }
- /*
- 're.Pattern="\[UPLOAD=(gif|jpg|jpeg|bmp)\](.[^\[]*)(gif|jpg|jpeg|bmp)\[\/UPLOAD\]"
- '$str= re.Replace($str,"<br><IMG SRC=\"image/$1.gif\" border=0>此主题相关链接如下:<br><A HREF=\"$2$1\" TARGET=_blank><IMG SRC=\"$2$1\" border=0 alt=按此在新窗口浏览图片 onload=\"javascript:if(this.width>screen.width-333)this.width=screen.width-333\"></A>")
- 're.Pattern="\[UPLOAD=(doc|xls|ppt|htm|swf|rar|zip|exe)\](.[^\[]*)(doc|xls|ppt|htm|swf|rar|zip|exe)\[\/UPLOAD\]"
- '$str= re.Replace($str,"<br><IMG SRC=\"image/$1.gif\" border=0>此主题相关链接如下:<br><a href=\"$2$1\" target='_blank'>点击浏览该文件</a>")
- '自动识别网址
- 're.Pattern = "^((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\':+!]+)"
- '$str = re.Replace($str,"<img align=absmiddle src=image/url.gif border=0><a target=_blank href=$1>$1</a>")
- 're.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\':+!]+)$"
- '$str = re.Replace($str,"<img align=absmiddle src=image/url.gif border=0><a target=_blank href=$1>$1</a>")
- 're.Pattern = "([^>=\"])((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9\./=\?%\-&_~`@[\]\':+!]+)"
- '$str = re.Replace($str,"$1<img align=absmiddle src=image/url.gif border=0><a target=_blank href=$2>$2</a>")
- '自动识别www等开头的网址
- 're.Pattern = "([^(http://|http:\\)])((www|cn)[.](\w)+[.]{1,}(net|com|cn|org|cc)(((\/[\~]*|\\[\~]*)(\w)+)|[.](\w)+)*(((([?](\w)+){1}[=]*))*((\w)+){1}([\&](\w)+[\=](\w)+)*)*)"
- '$str = re.Replace($str,"<img align=absmiddle src=image/url.gif border=0><a target=_blank href=http://$2>$2</a>")
- 're.Pattern="\[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/SHADOW]"
- '$str=re.Replace($str,"<div style=\"width:$1;filter:shadow(color=$2, strength=$3)\">$4</div>")
- 're.Pattern="\[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)\](.[^\[]*)\[\/GLOW]"
- '$str=re.Replace($str,"<div style=\"width:$1;filter:glow(color=$2, strength=$3)\">$4</div>")
- */
- ?>
Tags: 代码 转换成 html
- 上一篇:php 分析rss代码一段
- 下一篇:php模板
相关文章
- ·自动发布新闻的php代码(2013-12-08)
- ·php 分析rss代码一段(2013-12-08)
- ·php测试代码执行消耗的内存和时间(2014-01-06)
- ·phpmailer发送邮件代码(2014-01-21)
- ·php 发送邮件与pop3邮件登录代码(2014-01-21)
- ·php fsockopen邮箱发送实例代码(2014-01-22)
- ·301重定向代码(php apache) (2014-05-13)
- ·php 打印乘法口绝表代码(2014-05-19)
- ·PHP连接Memcache程序代码(2014-06-10)
- ·php读取本地php文件源代码输出显示(2014-06-14)
- ·PHP编程之代码命名规范(2014-06-14)
- ·php版淘宝网查询商品接口代码(2014-06-17)
- ·PHP把16进制的编码转为中文程序代码(2014-06-21)
- ·php开发中实用的PHP代码片段(2014-06-25)
- ·php判断ip黑名单程序代码(2014-07-01)
- ·PHP网址缩短代码(生成短网址)(2014-07-02)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)