PHP's program to convert UBB code into HTML code

Source: Internet
Author: User
Tags rar zip

<?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);

Picture Ubb
$str = Preg_replace ("/\[img\] (http|https|ftp): \/\/(. [ ^\[]*) \[\/img\]/i "," <a onfocus=\ "This.blur () \" href=\ "\${1}://\${2}\" Target=new>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>300) This.width=300\ "></a>", $str);

$str = Preg_replace ("/(\[img\]) images\/face\/em (. *?) \.gif (\[\/img\])/I "," ", $str);
Link 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);
Mailbox Ubb
$str = Preg_replace ("/(\[email\])" (. *?) (\[\/email\])/I "," <a href=\ "mailto:\${2}\ ">\${2}</a> ", $STR);
$str = Preg_replace ("/\[email=" (. [ ^\[]*) \]/i "," " "src=\" image/email1.gif\ "><a href=\"mailto:\${1}\"target=\" new\ ">", $str);
QQ number 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\ ">http://wpa.qq.com/pa?p=1:\${2}:\${1}\"Alt=\" Click here to send me a message \ "></a>", $str);
Color UBB
$str = Preg_replace ("/\[color=" (. [ ^\[]*) \]/i "," <font color=\ "\${1}\" > ", $str);
Text Font UBB
$str = Preg_replace ("/\[font=" (. [ ^\[]*) \]/i "," <font face=\ "\${1}\" > ", $str);
Text Size 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);
Text alignment UBB
$str = Preg_replace ("/\[align= (center|left|right) \]/i", "<div align=\" \${1}\ ">", $str);
Table Ubb
$str = Preg_replace ("/\[table=" (. [ ^\[]*) \]/i "," "<table width=\" \${1}\ "border=\" 1\ "style=\" border-collapse:collapse\ ">", $str);
Table UBB2
$str = Preg_replace ("/\[td=" ([0-9]*), ([0-9]*), ([0-9]*) \]/i ", <td colspan=\" \${1}\ "rowspan=\" \${2}\ "width=\" \$ {3}\ ">", $str);
Font italic
$str = Preg_replace ("/\[i\") ((. | \ n) *?) \[\/i\]/i "," <i>\${1}</i> ", $str);
Flash animation UBB
$str = Preg_replace ("/(\[flash\])" (http:\/\/.[ ^\[]* (. swf)) (\[\/flash\])/I "," <a href=\ "\${2}\" target=\ "new\" >[full screen to enjoy]</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\" >[full screen to enjoy]</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\"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\"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 Play 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\" 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\" 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]", "[/II]", "[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=\ "Run code \ onclick=\" RunCode () \ "> <input type=\" button\ "value=\" copy code \ "Onclick=\" Copycode () \ "> <input type=\" button\ "value=\" Save code \ "Onclick=\" Savecode () \ "> <input type=\" button\ "value=\" Jump & nbsp;&nbsp; turn \ "onclick=\" Goto (prompt) (' Please enter the first few lines to jump to? ', ' 1 ') \   accesskey=\ "g\" > &nbsp; hint: You can modify some of the code before running </div> "," <div style=\ background: #E2F2FF; width:90%;height:auto;border:1px solid #3CAAEC;p adding: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> this topic is related to the following links: <br><a href=\ "$2$1\" target=_ Blank>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> this topic is related to the following links: <br><a href=\" $2$1\ "target= ' _ Blank ' > Click to browse the file </a> ')
' Automatically identify URLs
' Re. Pattern = "^" ((Http|https|ftp|rtsp|mms):(\/\/|\\\\) [a-za-z0-9\./=\?%\ -&_~ ' @[\]\ ': +!] +)"
' $str = Re. Replace ($str, "<a target=_blank href=$1>$1</a>")
' Re. Pattern = "((HTTP|HTTPS|FTP|RTSP|MMS):(\/\/|\\\\) [a-za-z0-9\./=\?%\ -&_~ ' @[\]\ ': +!] +)$"
' $str = Re. Replace ($str, "<a target=_blank href=$1>$1</a>")
' Re. Pattern = "([^>=\"]) ((HTTP|HTTPS|FTP|RTSP|MMS):(\/\/|\\\\) [a-za-z0-9\./=\?%\ -&_~ ' @[\]\ ': +!] +)"
' $str = Re. Replace ($str, "$1<a target=_blank href=$2>$2</a>")
' Automatic identification of Web sites at the beginning of 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, "<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>")
*/
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.