[b]/[/b]、[u]/[/u][center]/[/center]、[fly]/[/fly] (marquee)[url=網址]文字[/url]、自動偵測 <a> 加 target=_blank[img]網址[/img]、[swf]、[dir]、[rm]、[mp]、[qt]:em1: ~ :em16: 對應 emot/em1.gif...[quote]、[color]、[size]、[face] (透過 UbbStr 處理,未列出完整碼)Function Ubb2Html(str, showEmot, showImg)
On Error Resume Next
If Not str <> "" Then Exit Function
Dim tmpStr : tmpStr = "uNobwab"
str = UbbStr(str, "url")
str = UbbStr(str, "quote")
str = UbbStr(str, "color")
str = UbbStr(str, "size")
str = UbbStr(str, "face")
If showEmot Then
Dim i
For i = 1 To 16
str = Replace(str, ":em" & i & ":", "
", 1, 6, 1)
str = Replace(str, ":em" & i & ":", "", 1, -1, 1)
Next
End If
If showImg Then
str = UbbStr(str, "img")
str = UbbStr(str, "swf")
str = UbbStr(str, "dir")
str = UbbStr(str, "rm")
str = UbbStr(str, "mp")
str = UbbStr(str, "qt")
End If
str = UbbStr(str, "frame")
' 簡單標籤直接替換
str = Replace(str, "[b]", "", 1, -1, 1)
str = Replace(str, "[/b]", "", 1, -1, 1)
str = Replace(str, "[u]", "", 1, -1, 1)
str = Replace(str, "[/u]", "", 1, -1, 1)
str = Replace(str, "[br]", "
", 1, -1, 1)
str = Replace(str, "[center]", "", 1, -1, 1)
str = Replace(str, "[/center]", " ", 1, -1, 1)
str = Replace(str, "[fly]", "", 1, -1, 1)
' 還原佔位符
str = Replace(str, "[" & tmpStr, "[", 1, -1, 1)
str = Replace(str, tmpStr & "]", "]", 1, -1, 1)
str = Replace(str, "/" & tmpStr, "/", 1, -1, 1)
Ubb2Html = str
End Function
UbbStr 函數未在片段中定義,無法完整執行。[url=javascript:alert(1)])未處理。Replace 參數 1, -1, 1 表示從第 1 字元開始、全部替換、二進位比較 (vbBinaryCompare)。Replace 邏輯不明(先換圖再清空?)。採用成熟解析器(如 BBCodeParser 移植版)或前端編輯器(CKEditor、TinyMCE)輸出 HTML 再經伺服端白名單清理(HtmlSanitizer)。