L'idée est de sa baser sur un code fonctionnel en PHP qui converti les caractères UTF-8 par leur équivalent HTML.
Exemple : Ł sera converti en Voici le code PHP que j'ai traduis :
Code PHP : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?
function utf8_to_html($data){
	return preg_replace("/([\\xC0-\\xF7]{1,1}[\\x80-\\xBF]+)/e", '_utf8_to_html("\\1")', $data);
}
 
function _utf8_to_html($data){
	$ret = 0;
	foreach((str_split(strrev(chr((ord($data{0}) % 252 % 248 % 240 % 224 % 192) + 128) . substr($data, 1)))) as $k => $v)
		$ret += (ord($v) % 128) * pow(64, $k);
	return "&#$ret;";
}
 
echo utf8_to_html(file_get_contents('mon_fichier_utf-8.txt'));
?>

Voici ma traduction :
Code ASP : Sélectionner tout - Visualiser dans une fenêtre à part
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)
%>

Le trace dans la fonction ASP utf8_to_html montre que ce qui est matché, est en fait les caractères suivants le caractère UTF-8 à convertir.
Pourtant les regexp ne sont-elles pas universelles ?

Si quelqu'un à une idée..

A noter que les scripts sont utilisés sur des documents encodés en ANSI et non UTF-8 sinon ça n'a aucun intérêt.
Par contre, mon_fichier_utf-8.txt est encodé en UTF-8 sans BOM.