1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| <%
Response.CodePage="28591"
Response.Charset="ISO-8859-1"
function str_split(str)
dim tab()
redim tab(len(str))
for i=0 to len(str)
tab(i)=mid(str, i+1, 1)
next
str_split=tab
end function
function strrev(strOrig)
dim strReverse
For x = Len(strOrig) To 1 Step -1
charA = Mid(strOrig, x, 1)
strReverse = strReverse & charA
Next
strrev=strReverse
end function
function sub_utf8_to_html(data)
dim v
ret=0
for k=0 to Ubound(str_split(strrev(Chr((asc(mid(data, 1, 1)) mod 252 mod 248 mod 240 mod 224 mod 192) + 128) & mid(data, 2))))-1
v=(str_split(strrev(Chr((asc(mid(data, 1, 1)) mod 252 mod 248 mod 240 mod 224 mod 192) + 128) & mid(data, 2)))(k))
ret=ret+((asc(v) mod 128) * (64^k))
next
sub_utf8_to_html="&#"&ret&";"
end function
function utf8_to_html(data)
Set objRegExp=New RegExp
objRegExp.Global=True
objRegExp.IgnoreCase=true
objRegExp.Pattern="([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)"
objRegExp.MultiLine=true
newstr=data
Set Matches = objRegExp.Execute(newstr)
if Matches.Count>0 then
For Match=0 to Matches.count-1
echo "Found : "&Matches(Match)&"<br>"
newstr=replace(newstr, Matches(Match), sub_utf8_to_html(Matches(Match)))
next
end if
utf8_to_html=newstr
set objRegExp = nothing
end function
sub echo(s)
response.write s
end sub
chaine = ""
Set ASPTear = Server.CreateObject("SOFTWING.ASPTear")
chaine = ASPTear.Retrieve(Cstr("http://www.monsite.com/mon_fichier_utf-8.txt"), 2, "", "", "")
Set ASPTear=Nothing
echo "Source : "&chaine&VbCrLf&"<br>"&VbCrLf&"<br>"&VbCrLf
echo "Convert : "&utf8_to_html(chaine)
%> |
Partager