fckeditor多种现象出现乱码的解决办法
在此我先说明我的fckeditor版本是2.4.1版本,网站编码采用GB2312,在上传含有中文的文件时,会出现乱码。在此作个记号。
ASP:
1。将class_upload.asp 、connector.asp两个文件中的utf-8改成GBK,结果连浏览的文件也会显示乱码,看来这个办法行不通。由于connector.asp中含有Session.CodePage ,每改一次编码就重新登陆一次。
2。网上还有将frmupload.html和frmresourcelist.html加utf-8,但在这个版本中行不通。上传的文件依旧乱码。在此附上两个互换函数。
Function GBtoUTF8(szInput)
Dim wch, uch, szRet
Dim x
Dim nAsc, nAsc2, nAsc3
If szInput = "" Then
GBtoUTF8= szInput
Exit Function
End If
For x = 1 To Len(szInput)
wch = Mid(szInput, x, 1)
nAsc = AscW(wch)
If nAsc < 0 Then nAsc = nAsc + 65536
If (nAsc And &HFF80) = 0 Then
szRet = szRet & wch
Else
If (nAsc And &HF000) = 0 Then
uch = "%" & Hex(((nAsc \ 2 ^ 6)) Or &HC0) & Hex(nAsc And &H3F Or &H80)
szRet = szRet & uch
Else
uch = "%" & Hex((nAsc \ 2 ^ 12) Or &HE0) & "%" & _
Hex((nAsc \ 2 ^ 6) And &H3F Or &H80) & "%" & _
Hex(nAsc And &H3F Or &H80)
szRet = szRet & uch
End If
End If
Next
GBtoUTF8= szRet
End Function
response.write(GBtoUTF8("中文短信UTF-8编码")&"<br><br>")
response.write(UTF2GB(GBtoUTF8("中文短信UTF-8编码"))&"<br><br>")
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) >= Dig+8 then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end function
function ConvChinese(x)
A=split(mid(x,2),"%")
i=0
j=0
for i=0 to ubound(A)
A(i)=c16to2(A(i))
next
for i=0 to ubound(A)-1
DigS=instr(A(i),"0")
Unicode=""
for j=1 to DigS-1
if j=1 then
A(i)=right(A(i),len(A(i))-DigS)
Unicode=Unicode & A(i)
else
i=i+1
A(i)=right(A(i),len(A(i))-2)
Unicode=Unicode & A(i)
end if
next
if len(c2to16(Unicode))=4 then
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
else
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
end if
next
end function
function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next
end function
function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function
function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end function
function c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x<2^DigS then
exit do
else
DigS=DigS+1
end if
loop
tempnum=x
i=0
for i=DigS to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function
晕死,这个版本是不会乱码的,原因是k-meleon ccf me 0.85不会自动更新缓存,我手工更新后,于是正常。在此之前用ff也是正常的。汗,白忙活了一天……
PHP:
1。上传乱码(显示肯定会乱码啦)
修改commands.php(154行),
在$sFileName = SanitizeFileName( $sFileName ) ;(154行)后面添加:$sFileName = iconv("UTF-8″,"gb2312″,$sFileName);
2。浏览乱码(上传是正常的,但显示却是乱码)
修改util.php:
修改return utf8_encode( htmlspecialchars( $value ) ) ;(50行)为:return iconv( "GBK", "UTF-8", htmlspecialchars($value) ) ;
感觉改为:return (mb_convert_encoding(htmlspecialchars($value),"UTF-8","GBK")) ;更合适。
修改 frmresourcelist.html 文件encodeURI( fileUrl ).replace( '#', '%23' )(第78行)为:
fileUrl.replace( '#', '%23' )
4。创建中文文件夹乱码
修改io.php
第67行(在CreateServerFolder函数里):添加$folderPath = iconv("utf-8","gbk",$folderPath);
- 没有相关文章
- 没有评论