| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:求助,ubb代码在utf-8编码下出错
只看楼主 加入收藏
enjoy535
Rank: 1
等 级:新手上路
帖 子:114
专家分:3
注 册:2007-1-16
结帖率:40%
收藏
 问题点数:0 回复次数:2 
求助,ubb代码在utf-8编码下出错
近段时间在忙着把网站由原来的gb2312编码转换为utf-8编码,眼看快完成了,今天测试时却突然发现UBB代码转换出了问题,想请教各位达人帮忙解答解答

UBB代码在之前一直使用正常,在转换成utf-8编码后,所有图片和FLASH,只要是UBB代码中间包含了网址的全都不能正常显示
原本应该是“/”的转换后全都变成了“/]”
我的网站是ASP网站

例如:
UBB代码:
[IMG]http://www.[/IMG]

原gb2312编码下转换后为
<IMG src="http://www.
图片能正常显示

但转换为UTF-8编码后就变成了
<IMG src="http:/]/]www.]data/]attachment/]forum/]201108/]22/]003952l5b58n8gsn5iv52n.jpg">
无法显示图片

其他的FLASH等也是类似症状

请哪位高手帮忙解答一下啊
UBB源代码放在了附件里,也贴在二楼了,但是好像有些显示不正常
引用方式如<%= ubb2html(rs_detail_bg("bg_content"))%>
in_ubb.rar (2.28 KB)


[ 本帖最后由 enjoy535 于 2011-8-31 21:24 编辑 ]
搜索更多相关主题的帖子: ASP网站 FLASH 图片 
2011-08-31 21:18
enjoy535
Rank: 1
等 级:新手上路
帖 子:114
专家分:3
注 册:2007-1-16
收藏
得分:0 
<%

'---------------HTML代码过滤-----------
function HTMLEncode(fString)
  if not isnull(fString) then
    fString = replace(fString, ">", "&gt;")
    fString = replace(fString, "<", "&lt;")
    fString = Replace(fString, CHR(32), "&nbsp;")
    fString = Replace(fString, CHR(9), "&nbsp;")
    fString = Replace(fString, CHR(34), "&quot;")
    fString = Replace(fString, CHR(39), "'")
    fString = Replace(fString, CHR(13), "")
    fString = Replace(fString, CHR(10) & CHR(10), "</P><br/><p>")
    fString = Replace(fString, CHR(10), "<p>")
    fString = Replace(fString, CHR(36), "$")
    HTMLEncode = fString
  End IF
end function

'----------------SQL过滤---------------
function filter(text)
  if isnull(text) then
    filter=""
    exit function
  End IF
  filter=replace(text,"'","''")
end function

'---------------------------------------

Function ubb2html(content)
  On Error Resume Next
  content=trim(content)
    content=HTMLEncode(content)
  Dim nowtime, i
  ubb = content
  nowtime = Now()

  ubb = Convert(ubb, "code")
  ubb = Convert(ubb, "html")
  ubb = Convert(ubb, "url")
  ubb = Convert(ubb, "color")
  ubb = Convert(ubb, "font")
  ubb = Convert(ubb, "size")
  ubb = Convert(ubb, "quote")
  ubb = Convert(ubb, "email")
  ubb = Convert(ubb, "img")
  ubb = Convert(ubb, "swf")
  ubb = Replace(ubb, "", "<b>", 1, -1, 1)
  ubb = Replace(ubb, "
", "</b>", 1, -1, 1)
  ubb = Replace(ubb, "", "<i>", 1, -1, 1)
  ubb = Replace(ubb, "
", "</i>", 1, -1, 1)
  ubb = Replace(ubb, "", "<u>", 1, -1, 1)
  ubb = Replace(ubb, "
", "</u>", 1, -1, 1)
  ubb = Replace(ubb, "[center]", "<center>", 1, -1, 1)
  ubb = Replace(ubb, "[/center]", "</center>", 1, -1, 1)

  For i = 1 To 28
      ubb = Replace(ubb, "{:em" & i & "}", "<IMG SRC=emot/emotface/em" & i & ".gif></img>", 1, 6, 1)
      ubb = Replace(ubb, "{:em" & i & "}", "", 1, -1, 1)
  Next
  ubb = Replace(ubb, "[" & Chr(176), "[", 1, -1, 1)
  ubb = Replace(ubb, Chr(176) & "]", "]", 1, -1, 1)
  ubb = Replace(ubb, "/" & Chr(176), "/", 1, -1, 1)
  ' ubb=Replace(ubb,"{;em","{:em",1,-1,1)
ubb2html = ubb
End Function

'================================================================================Ubb代码解析函数Convert
Private Function Convert(ubb, CovT)
  On Error Resume Next
  Dim cText, startubb, endubb, Lcovt, text, codetext
  cText = ubb
  startubb = 1
  Do While CovT = "url" Or CovT = "color" Or CovT = "font" Or CovT = "size"
     startubb = InStr(startubb, cText, "[" & CovT & "=", 1)
     If startubb = 0 Then
        Exit Do
     End If
     endubb = InStr(startubb, cText, "]", 1)
     If endubb = 0 Then
        Exit Do
     End If
     Lcovt = CovT
     startubb = startubb + Len(Lcovt) + 2
     text = Mid(cText, startubb, endubb - startubb)
     codetext = Replace(text, "[", "[" & Chr(176), 1, -1, 1)
     codetext = Replace(codetext, "]", Chr(176) & "]", 1, -1, 1)
     'codetext=Replace(codetext,"{:em","{;em",1,-1,1)
    codetext = Replace(codetext, "/", "/" & Chr(176), 1, -1, 1)
    Select Case CovT
        Case "color"
             cText = Replace(cText, "[color=" & text & "]", "<font color='" & text & "'>", 1, 1, 1)
             cText = Replace(cText, "[/color]", "</font>", 1, 1, 1)
        Case "font"
             cText = Replace(cText, "", "<font face='" & text & "'>", 1, 1, 1)
             cText = Replace(cText, "
", "</font>", 1, 1, 1)
        Case "size"
             If IsNumeric(text) Then
                If text > 6 Then
                   text = 6
                End If
                If text < 1 Then
                   text = 1
                End If
                cText = Replace(cText, "[size=" & text & "]", "<font size='" & text & "'>", 1, 1, 1)
                cText = Replace(cText, "[/size]", "</font>", 1, 1, 1)
             End If
        Case "url"
             cText = Replace(cText, "[url=" & text & "]", "<a href='" & codetext & "' target=_blank>", 1, 1, 1)
             cText = Replace(cText, "[/url]", "</a>", 1, 1, 1)
        Case "email"
             cText = Replace(cText, "[" & CovT & "=" & text & "]", "<a href=mailto:" & text & ">", 1, 1, 1)
             cText = Replace(cText, "[/" & CovT & "]", "</a>", 1, 1, 1)
        End Select
     Loop
     startubb = 1
  Do
     startubb = InStr(startubb, cText, "[" & CovT & "]", 1)
     If startubb = 0 Then
        Exit Do
     End If
     endubb = InStr(startubb, cText, "[/" & CovT & "]", 1)
     If endubb = 0 Then
        Exit Do
     End If
     Lcovt = CovT
     startubb = startubb + Len(Lcovt) + 2
     text = Mid(cText, startubb, endubb - startubb)
     codetext = Replace(text, "[", "[" & Chr(176), 1, -1, 1)
     codetext = Replace(codetext, "]", Chr(176) & "]", 1, -1, 1)
     'codetext=Replace(codetext,"{:em","{;em",1,-1,1)
     codetext = Replace(codetext, "/", "/" & Chr(176), 1, -1, 1)
     Select Case CovT
         Case "url"
              cText = Replace(cText, "[" & CovT & "]" & text, "<a href='" & codetext & "' target=_blank>" & codetext, 1, 1, 1)
              cText = Replace(cText, "<a href='" & codetext & "' target=_blank>" & codetext & "[/" & CovT & "]", "<a href=" & codetext & " target=_blank>" & codetext & "</a>", 1, 1, 1)
         Case "email"
              cText = Replace(cText, "[" & CovT & "]", "<a href=mailto:" & text & ">", 1, 1, 1)
              cText = Replace(cText, "[/" & CovT & "]", "</a>", 1, 1, 1)
         Case "html"
              codetext = Replace(codetext, "<br>", Chr(13), 1, -1, 1)
              codetext = Replace(codetext, " ", Chr(32), 1, -1, 1)
              Randomize
              rid = "temp" & Int(100000 * Rnd)
              cText = Replace(cText, "[html]" & text, "代码片断如下:<TEXTAREA id=" & rid & " rows=15 style='width:100%' class='bk'>" & codetext, 1, 1, 1)
              cText = Replace(cText, "代码片断如下:<TEXTAREA id=" & rid & " rows=15 style='width:100%' class='bk'>" & codetext & "[/html]", "代码片断如下:<TEXTAREA id=" & rid & " rows=15 style='width:100%' class='bk'>" & codetext & "</TEXTAREA><INPUT onclick=runEx('" & rid & "') type=button value=运行此段代码 name=Button1 class='Tips_bo'> <INPUT onclick=JM_cc('" & rid & "') type=button value=复制到我的剪贴板 name=Button2 class='Tips_bo'>", 1, 1, 1)
         Case "img"
              cText = Replace(cText, "[img]" & text, "<img src="&codetext, 1, 1, 1)
              cText = Replace(cText, "[/img]", " >", 1, 1, 1)
         Case "code"
              cText = Replace(cText, "
" & text, "以下内容为程序代码<hr noshade>" & codetext, 1, 1, 1)
              cText = Replace(cText, "以下内容为程序代码<hr noshade>" & codetext & "
", "以下内容为程序代码<hr noshade>" & codetext & "<hr noshade>", 1, 1, 1)
         Case "quote"
              atext = Replace(text, "[img]", "", 1, -1, 1)
              atext = Replace(atext, "[/img]", "", 1, -1, 1)
              atext = Replace(atext, "[swf]", "", 1, -1, 1)
              atext = Replace(atext, "[/swf]", "", 1, -1, 1)
              atext = Replace(atext, "[html]", "", 1, -1, 1)
              atext = Replace(atext, "[/html]", "", 1, -1, 1)
              ' atext=Replace(atext,"{:em","{;em",1,-1,1)
              atext = Split(atext, 350)
              atext = Replace(atext, Chr(32), " ", 1, -1, 1)
              cText = Replace(cText, "
" & text, "<blockquote><hr noshade>" & atext, 1, 1, 1)
              cText = Replace(cText, "<blockquote><hr noshade>" & atext & "
", "<blockquote><hr noshade>" & atext & "<hr noshade></blockquote>", 1, 1, 1)
         Case "swf"
              cText = Replace(cText, "[swf]" & text, "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.,0,0,0' width='500' height='500'><param name=movie value='" & codetext & "'><param name=quality value=high><embed src='" & codetext & "' quality=high pluginspage='http://www.' type='application/x-shockwave-flash' width='500' height='500'>", 1, 1, 1)
              cText = Replace(cText, "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.,0,0,0' width='500' height='500'><param name=movie value='" & codetext & "'><param name=quality value=high><embed src='" & codetext & "' quality=high pluginspage='http://www.' type='application/x-shockwave-flash' width='500' height='500'>" & "[/swf]", "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.,0,0,0' width='500' height='500'><param name=movie value='" & codetext & "'><param name=quality value=high><embed src='" & codetext & "' quality=high pluginspage='http://www.' type='application/x-shockwave-flash' width='500' height='500'>" & "</embed></object>", 1, 1, 1)
         End Select
      Loop
      Convert = cText
End Function


 %>

[ 本帖最后由 enjoy535 于 2011-8-31 21:32 编辑 ]

2011-08-31 21:19
enjoy535
Rank: 1
等 级:新手上路
帖 子:114
专家分:3
注 册:2007-1-16
收藏
得分:0 
目前我只能勉强在最后面加一句
    ubb = Replace(ubb, "/]", "/", 1, -1, 1)
来缓解上面的错误,但又害怕会出现其他乱码

2011-08-31 21:36
快速回复:求助,ubb代码在utf-8编码下出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015078 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved