#101895 - 2003-06-09 10:49 PM
Re: HTMLtoText, has anyone done that?
|
masken
MM club member
   
Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
|
hmm... I think we have something here? Comments, errors?
I'm a bit worried about the "$Char = $Chars[$AltAPos]", cause that will result in a stop if the code isn't found (-1 returned)...
code:
FUNCTION HTMLtoText($string) ;| Exit if there's nothing to convert IF INSTR($string, "&") = 0 OR INSTR($string, ";") = 0 EXIT 2 ENDIF DIM $Counter DIM $CodeAlts[102] $CodeAlts[0] = """ $CodeAlts[1] = "&" $CodeAlts[2] = "<" $CodeAlts[3] = ">" $CodeAlts[4] = "™" $CodeAlts[5] = " " $CodeAlts[6] = "¡" $CodeAlts[7] = "¢" $CodeAlts[8] = "£" $CodeAlts[9] = "¤" $CodeAlts[10] = "¥" $CodeAlts[11] = "¦" $CodeAlts[12] = "§" $CodeAlts[13] = "¨" $CodeAlts[14] = "©" $CodeAlts[15] = "ª" $CodeAlts[16] = "«" $CodeAlts[17] = "¬" $CodeAlts[18] = "­" $CodeAlts[19] = "®" $CodeAlts[20] = "¯" $CodeAlts[21] = "°" $CodeAlts[22] = "±" $CodeAlts[23] = "²" $CodeAlts[24] = "³" $CodeAlts[25] = "´" $CodeAlts[26] = "µ" $CodeAlts[27] = "¶" $CodeAlts[28] = "·" $CodeAlts[29] = "¸" $CodeAlts[30] = "¹" $CodeAlts[31] = "º" $CodeAlts[32] = "»" $CodeAlts[33] = "¼" $CodeAlts[34] = "½" $CodeAlts[35] = "¾" $CodeAlts[36] = "¿" $CodeAlts[37] = "À" $CodeAlts[38] = "Á" $CodeAlts[39] = "Â" $CodeAlts[40] = "Ã" $CodeAlts[41] = "Ä" $CodeAlts[42] = "Å" $CodeAlts[43] = "Æ" $CodeAlts[44] = "Ç" $CodeAlts[45] = "È" $CodeAlts[46] = "É" $CodeAlts[47] = "Ê" $CodeAlts[48] = "Ë" $CodeAlts[49] = "Ì" $CodeAlts[50] = "Í" $CodeAlts[51] = "Î" $CodeAlts[52] = "Ï" $CodeAlts[53] = "ð" $CodeAlts[54] = "Ñ" $CodeAlts[55] = "Ò" $CodeAlts[56] = "Ó" $CodeAlts[57] = "Ô" $CodeAlts[58] = "Õ" $CodeAlts[59] = "Ö" $CodeAlts[60] = "×" $CodeAlts[61] = "Ø" $CodeAlts[62] = "Ù" $CodeAlts[63] = "Ú" $CodeAlts[64] = "Û" $CodeAlts[65] = "Ü" $CodeAlts[66] = "Ý" $CodeAlts[67] = "þ" $CodeAlts[68] = "ß" $CodeAlts[69] = "à" $CodeAlts[70] = "á" $CodeAlts[71] = "â" $CodeAlts[72] = "ã" $CodeAlts[73] = "ä" $CodeAlts[74] = "å" $CodeAlts[75] = "æ" $CodeAlts[76] = "ç" $CodeAlts[77] = "è" $CodeAlts[78] = "é" $CodeAlts[79] = "ê" $CodeAlts[80] = "ë" $CodeAlts[81] = "ì" $CodeAlts[82] = "í" $CodeAlts[83] = "î" $CodeAlts[84] = "ï" $CodeAlts[85] = "ð" $CodeAlts[86] = "ñ" $CodeAlts[87] = "ò" $CodeAlts[88] = "ó" $CodeAlts[89] = "ô" $CodeAlts[90] = "õ" $CodeAlts[91] = "ö" $CodeAlts[92] = "÷" $CodeAlts[93] = "ø" $CodeAlts[94] = "ù" $CodeAlts[95] = "ú" $CodeAlts[96] = "û" $CodeAlts[97] = "ü" $CodeAlts[98] = "ý" $CodeAlts[99] = "þ" $CodeAlts[100] = "ÿ" DIM $Chars[102] $Chars[0] = CHR(34) $Chars[1] = "&" $Chars[2] = "<" $Chars[3] = ">" $Chars[4] = "™" $Chars[5] = " " $Chars[6] = "¡" $Chars[7] = "¢" $Chars[8] = "£" $Chars[9] = "¤" $Chars[10] = "¥" $Chars[11] = "¦" $Chars[12] = "§" $Chars[13] = "¨" $Chars[14] = "©" $Chars[15] = "ª" $Chars[16] = "«" $Chars[17] = "¬" $Chars[18] = "" $Chars[19] = "®" $Chars[20] = "¯" $Chars[21] = "°" $Chars[22] = "±" $Chars[23] = "²" $Chars[24] = "³" $Chars[25] = "´" $Chars[26] = "µ" $Chars[27] = "¶" $Chars[28] = "·" $Chars[29] = "¸" $Chars[30] = "¹" $Chars[31] = "º" $Chars[32] = "»" $Chars[33] = "¼" $Chars[34] = "½" $Chars[35] = "¾" $Chars[36] = "¿" $Chars[37] = "À" $Chars[38] = "Á" $Chars[39] = "Â" $Chars[40] = "Ã" $Chars[41] = "Ä" $Chars[42] = "Å" $Chars[43] = "Æ" $Chars[44] = "Ç" $Chars[45] = "È" $Chars[46] = "É" $Chars[47] = "Ê" $Chars[48] = "Ë" $Chars[49] = "Ì" $Chars[50] = "Í" $Chars[51] = "Î" $Chars[52] = "Ï" $Chars[53] = "Ð" $Chars[54] = "Ñ" $Chars[55] = "Ò" $Chars[56] = "Ó" $Chars[57] = "Ô" $Chars[58] = "Õ" $Chars[59] = "Ö" $Chars[60] = "×" $Chars[61] = "Ø" $Chars[62] = "Ù" $Chars[63] = "Ú" $Chars[64] = "Û" $Chars[65] = "Ü" $Chars[66] = "Ý" $Chars[67] = "Þ" $Chars[68] = "ß" $Chars[69] = "à" $Chars[70] = "á" $Chars[71] = "â" $Chars[72] = "ã" $Chars[73] = "ä" $Chars[74] = "å" $Chars[75] = "æ" $Chars[76] = "ç" $Chars[77] = "è" $Chars[78] = "é" $Chars[79] = "ê" $Chars[80] = "ë" $Chars[81] = "ì" $Chars[82] = "í" $Chars[83] = "î" $Chars[84] = "ï" $Chars[85] = "ð" $Chars[86] = "ñ" $Chars[87] = "ò" $Chars[88] = "ó" $Chars[89] = "ô" $Chars[90] = "õ" $Chars[91] = "ö" $Chars[92] = "÷" $Chars[93] = "ø" $Chars[94] = "ù" $Chars[95] = "ú" $Chars[96] = "û" $Chars[97] = "ü" $Chars[98] = "ý" $Chars[99] = "þ" $Chars[100] = "ÿ"
$CodeTexts = SPLIT("$string", "&") FOR $Counter = 0 TO UBOUND($CodeTexts) IF INSTR($CodeTexts[$Counter], ";") <> 0 ;|We have an array element starting with a code, that perhaps also ;|contains some text after the code, substract the code-only part $Code = SPLIT($CodeTexts[$Counter], ";")[0] IF LEFT($Code, 1) = "#" ;|we have a numeric code $Char = CHR(SUBSTR($Code, 2, LEN($Code))) ELSE ;|we have an altcode $AltAPos = ASCAN($CodeAlts, "&" + $Code + ";") $Char = $Chars[$AltAPos] ENDIF ;|re-assemble the array element, there might be text after the code part $CodeTexts[$Counter] = $Char + SUBSTR($CodeTexts[$Counter], INSTR($CodeTexts[$Counter], ";") + 1, LEN($CodeTexts[$Counter])) ENDIF NEXT FOR EACH $Text IN $CodeTexts $HTMLtoText = $HTMLtoText + $Text NEXT ENDFUNCTION
[ 09. June 2003, 22:51: Message edited by: masken ]
_________________________
The tart is out there
|
|
Top
|
|
|
|
#101897 - 2003-06-09 11:29 PM
Re: HTMLtoText, has anyone done that?
|
masken
MM club member
   
Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
|
|
|
Top
|
|
|
|
#101904 - 2003-06-11 12:15 AM
Re: HTMLtoText, has anyone done that?
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 811 anonymous users online.
|
|
|