PHP's program to convert UBB code into HTML code _php tutorial

Source: Internet
Author: User
Tags rar
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 "," () this.width=300\ ">", $str);
$str = Preg_replace ("/\[img=* ([0-9]*), * ([0-9]*) \] (HTTP|HTTPS|FTP): \/\/(. [ ^\[]*) \[\/img\]/i "," () this.width=300\ ">", $str);

$str = Preg_replace ("/(\[img\]) images\/face\/em (. *?) \.gif (\[\/img\])/I "," ", $str);
Link UBB
$str = Preg_replace ("/(\[url\]) (. [ ^\[]*) (\[url\])/I "," \${1} ", $STR);
$str = Preg_replace ("/\[url= (. [ ^\[]*) \]/i "," ", $str);
Email UBB
$str = Preg_replace ("/(\[email\]) (. *?) (\[\/email\])/I "," Mailto:\${2}\ ">\${2}", $STR);
$str = Preg_replace ("/\[email= (. [ ^\[]*) \]/i "," mailto:\${1}\ "target=\" new\ ">", $str);
QQ number UBB
$str = Preg_replace ("/\[qq= ([0-9]*) \] ([0-9]*) \[\/qq\]/i", "", $str);
Color UBB
$str = Preg_replace ("/\[color= (. [ ^\[]*) \]/i "," ", $str);
Text Font UBB
$str = Preg_replace ("/\[font= (. [ ^\[]*) \]/i "," ", $str);
Text Size UBB
$str = Preg_replace ("/\[size= ([0-9]*) \]/i", "", $str);
$str = Preg_replace ("/\[size= ([0-9]*) pt\]/i", "", $str);
$str = Preg_replace ("/\[size= ([0-9]*) px\]/i", "", $str);
Text alignment UBB
$str = Preg_replace ("/\[align= (center|left|right) \]/i", "", $str);
Form Ubb
$str = Preg_replace ("/\[table= (. [ ^\[]*) \]/i ","

", $STR);Form UBB2$str = Preg_replace ("/\[td= ([0-9]*), ([0-9]*), ([0-9]*) \]/i", " "," "," ","
", $STR);
Font Tilt
$str = Preg_replace ("/\[i\" (. | \ n) *?) \[\/i\]/i ","\${1}", $STR);
Flash animation UBB
$str = Preg_replace ("/(\[flash\]) (http:\/\/.[ ^\[]* (. swf)) (\[\/flash\])/I "," [Full screen view]
\${2} ", $STR);
$str = Preg_replace ("/(\[flash=* ([0-9]*), * ([0-9]*) \]) (http:\/\/.[ ^\[]* (. swf)) (\[\/flash\])/I "," [Full screen view]
\${4} ", $STR);

MEDIA Play Play Ubb
$str = Preg_replace ("/\[wmv\" (. [ ^\[]*) \[\/wmv]/i ","", $STR);
$str = Preg_replace ("/\[wmv=* ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/wmv]/i ","", $STR);

Realplay Play Ubb
$str = Preg_replace ("/\[rm\" (. [ ^\[]*) \[\/rm]/i ","
", $STR);
$str = Preg_replace ("/\[rm=* ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/rm]/i ","
", $STR);
$str = Str_replace ("\ r \ n", "
", $STR);
$str = Preg_replace ("/\[rm=* ([0-9]*), * ([0-9]*) \] (. [ ^\[]*) \[\/rm]/i ","
", $STR);
/*
Re.pattern= "\[code\" ((. | \ n) *?) \[\/code\] "
Set Tempcodes=re. Execute ($STR)
For I=0 to Tempcodes.count-1
Re.pattern= "
"
Tempcode=replace (Tempcodes (i), "
", vbCrLf)
$str =replace ($str, Tempcodes (i), Tempcode)
Next
*/
$searcharray = Array ("[/url]", "[/email]", "[/color]", "[/size]", "[/font]", "[/align]", "[b]", "[/C]", "[U]", "[/U]", "[ List] "," [List=1] "," [List=a] "," [List=a] "," [*] "," [/list] "," [Indent] "," [/indent] "," [Discuz_code_0] "," [quote] "," [/ Quote] "," [tr] "," [TD] "," [/td] "," [/tr] "," [/table] ");
$replacearray = Array ("", "", "", "", "", "", "", "","", "", "
      ", "
        ", "
          ","
            ", "
          1. ", "
", "
", "
","<textarea name="\"codes\"" id="\"codes\"" rows="\"12\"" cols="\"65\"">","</textarea>
Tip: You can modify some of the code before running "," "," ","
","
");
for ($i =0; $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, "
RELATED links to this topic are as follows:
screen.width-333) this.width=screen.width-333\ ">")
' Re. Pattern= "\[upload= (Doc|xls|ppt|htm|swf|rar|zip|exe) \] (. [ ^\[]*) (Doc|xls|ppt|htm|swf|rar|zip|exe) \[\/upload\] "
' $str = Re. Replace ($str, "
RELATED links to this topic are as follows:
Click to browse the file ")
' Automatically identify URLs
' Re. Pattern = "^ ((http|https|ftp|rtsp|mms):(\/\/|\\\\) [a-za-z0-9\./=\?%\ -&_~ ' @[\]\ ': +!] +)"
' $str = Re. Replace ($STR, "$")
' Re. Pattern = "((HTTP|HTTPS|FTP|RTSP|MMS):(\/\/|\\\\) [a-za-z0-9\./=\?%\ -&_~ ' @[\]\ ': +!] +)$"
' $str = Re. Replace ($STR, "$")
' Re. Pattern = "([^>=\]") ((HTTP|HTTPS|FTP|RTSP|MMS):(\/\/|\\\\) [a-za-z0-9\./=\?%\ -&_~ ' @[\]\ ': +!] +)"
' $str = Re. Replace ($str, "$1$2")
' Automatically identify URLs at the beginning of www, etc.
' 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, "$")
' Re. Pattern= "\[shadow=* ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*] \] (. [ ^\[]*) \[\/shadow] "
' $str =re. Replace ($str, "$4")
' Re. Pattern= "\[glow=* ([0-9]*), * (#*[a-z0-9]*), * ([0-9]*] \] (. [ ^\[]*) \[\/glow] "
' $str =re. Replace ($str, "$4")
*/
?>

http://www.bkjia.com/PHPjc/631908.html www.bkjia.com true http://www.bkjia.com/PHPjc/631908.html techarticle php function Ubbcode ($STR) {//$str = Str_replace (file:,file:, $str);//$str = Str_replace (files:,files:, $str);//$s TR = Str_replace (script:,script:, $STR); $str = Str_replace (J ...

  • 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.