#101889 - 2003-06-09 04:45 PM
Re: HTMLtoText, has anyone done that?
|
masken
MM club member
   
Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
|
Yeah... you're right avout the ASCII codes there Richard. But I think in webpages, it's a static table? Ie; the one below? This would also make sure any local OS language gets the codes right?
Right now though.. now why doesn't this work? ASCAN() always returns -1. the IF NOT case still kicks in too
code:
FUNCTION HTMLtoText($string) ;| Exit if there's nothing to convert IF INSTR($string, "&") = 0 OR INSTR($string, ";") = 0 EXIT 2 ENDIF
DIM $Codes[157] $Codes[0] = CHR(9) + "&&" + "	" $Codes[1] = CHR(10) + "&&" + " " $Codes[2] = CHR(13) + "&&" + " " $Codes[3] = " " + "&&" + " " $Codes[4] = "!" + "&&" + "!" $Codes[5] = CHR(34) + "&&" + """ + "&&" + """ $Codes[6] = "#" + "&&" + "#" $Codes[7] = CHR(36) + "&&" + "$" $Codes[8] = "%" + "&&" + "%" $Codes[9] = "&" + "&&" + "&" + "&&" + "&" $Codes[10] = CHR(39) + "&&" + "'" $Codes[11] = "(" + "&&" + "(" $Codes[12] = ")" + "&&" + ")" $Codes[13] = "*" + "&&" + "*" $Codes[14] = "+" + "&&" + "+" $Codes[15] = "," + "&&" + "," $Codes[16] = "-" + "&&" + "-" $Codes[17] = "." + "&&" + "." $Codes[18] = "/" + "&&" + "/" $Codes[19] = ":" + "&&" + ":" $Codes[20] = ";" + "&&" + ";" $Codes[21] = "<" + "&&" + "<" + "&&" + "<" $Codes[22] = "=" + "&&" + "=" $Codes[23] = ">" + "&&" + ">" + "&&" + ">" $Codes[24] = "?" + "&&" + "?" $Codes[25] = "@" + "&&" + "@" $Codes[26] = "[" + "&&" + "[" $Codes[27] = "\" + "&&" + "\" $Codes[28] = "]" + "&&" + "]" $Codes[29] = "^" + "&&" + "^" $Codes[30] = "_" + "&&" + "_" $Codes[31] = "`" + "&&" + "`" $Codes[32] = "{" + "&&" + "{" $Codes[33] = "|" + "&&" + "|" $Codes[34] = "}" + "&&" + "}" $Codes[35] = "~" + "&&" + "~" $Codes[36] = "‚" + "&&" + "‚" $Codes[37] = "ƒ" + "&&" + "ƒ" $Codes[38] = "„" + "&&" + "„" $Codes[39] = "…" + "&&" + "…" $Codes[40] = "†" + "&&" + "†" $Codes[41] = "‡" + "&&" + "‡" $Codes[42] = "ˆ" + "&&" + "ˆ" $Codes[43] = "‰" + "&&" + "‰" $Codes[44] = "Š" + "&&" + "Š" $Codes[45] = "‹" + "&&" + "‹" $Codes[46] = "Œ" + "&&" + "Œ" $Codes[47] = "‘" + "&&" + "‘" $Codes[48] = "’" + "&&" + "’" $Codes[49] = "“" + "&&" + "“" $Codes[50] = "”" + "&&" + "”" $Codes[51] = "•" + "&&" + "•" $Codes[52] = "–" + "&&" + "–" $Codes[53] = "—" + "&&" + "—" $Codes[54] = "˜" + "&&" + "˜" $Codes[55] = "™" + "&&" + "™" + "&&" + "™" $Codes[56] = "š" + "&&" + "š" $Codes[57] = "›" + "&&" + "›" $Codes[58] = "œ" + "&&" + "œ" $Codes[59] = "Ÿ" + "&&" + "Ÿ" $Codes[60] = " " + "&&" + " " + "&&" + " " $Codes[61] = "¡" + "&&" + "¡" + "&&" + "¡" $Codes[62] = "¢" + "&&" + "¢" + "&&" + "¢" $Codes[63] = "£" + "&&" + "£" + "&&" + "£" $Codes[64] = "¤" + "&&" + "¤" + "&&" + "¤" $Codes[65] = "¥" + "&&" + "¥" + "&&" + "¥" $Codes[66] = "¦" + "&&" + "¦" + "&&" + "¦" $Codes[67] = "§" + "&&" + "§" + "&&" + "§" $Codes[68] = "¨" + "&&" + "¨" + "&&" + "¨" $Codes[69] = "©" + "&&" + "©" + "&&" + "©" $Codes[70] = "ª" + "&&" + "ª" + "&&" + "ª" $Codes[71] = "«" + "&&" + "«" + "&&" + "«" $Codes[72] = "¬" + "&&" + "¬" + "&&" + "¬" $Codes[73] = "" + "&&" + "­" + "&&" + "­" $Codes[74] = "®" + "&&" + "®" + "&&" + "®" $Codes[75] = "¯" + "&&" + "¯" + "&&" + "¯" $Codes[76] = "°" + "&&" + "°" + "&&" + "°" $Codes[77] = "±" + "&&" + "±" + "&&" + "±" $Codes[78] = "²" + "&&" + "²" + "&&" + "²" $Codes[79] = "³" + "&&" + "³" + "&&" + "³" $Codes[80] = "´" + "&&" + "´" + "&&" + "´" $Codes[81] = "µ" + "&&" + "µ" + "&&" + "µ" $Codes[82] = "¶" + "&&" + "¶" + "&&" + "¶" $Codes[83] = "·" + "&&" + "·" + "&&" + "·" $Codes[84] = "¸" + "&&" + "¸" + "&&" + "¸" $Codes[85] = "¹" + "&&" + "¹" + "&&" + "¹" $Codes[86] = "º" + "&&" + "º" + "&&" + "º" $Codes[87] = "»" + "&&" + "»" + "&&" + "»" $Codes[88] = "¼" + "&&" + "¼" + "&&" + "¼" $Codes[89] = "½" + "&&" + "½" + "&&" + "½" $Codes[90] = "¾" + "&&" + "¾" + "&&" + "¾" $Codes[91] = "¿" + "&&" + "¿" + "&&" + "¿" $Codes[92] = "À" + "&&" + "À" + "&&" + "À" $Codes[93] = "Á" + "&&" + "Á" + "&&" + "Á" $Codes[94] = "Â" + "&&" + "Â" + "&&" + "Â" $Codes[95] = "Ã" + "&&" + "Ã" + "&&" + "Ã" $Codes[96] = "Ä" + "&&" + "Ä" + "&&" + "Ä" $Codes[97] = "Å" + "&&" + "Å" + "&&" + "Å" $Codes[98] = "Æ" + "&&" + "Æ" + "&&" + "Æ" $Codes[99] = "Ç" + "&&" + "Ç" + "&&" + "Ç" $Codes[100] = "È" + "&&" + "È" + "&&" + "È" $Codes[101] = "É" + "&&" + "É" + "&&" + "É" $Codes[102] = "Ê" + "&&" + "Ê" + "&&" + "Ê" $Codes[103] = "Ë" + "&&" + "Ë" + "&&" + "Ë" $Codes[104] = "Ì" + "&&" + "Ì" + "&&" + "Ì" $Codes[105] = "Í" + "&&" + "Í" + "&&" + "Í" $Codes[106] = "Î" + "&&" + "Î" + "&&" + "Î" $Codes[107] = "Ï" + "&&" + "Ï" + "&&" + "Ï" $Codes[108] = "Ð" + "&&" + "Ð" + "&&" + "ð" $Codes[109] = "Ñ" + "&&" + "Ñ" + "&&" + "Ñ" $Codes[110] = "Ò" + "&&" + "Ò" + "&&" + "Ò" $Codes[111] = "Ó" + "&&" + "Ó" + "&&" + "Ó" $Codes[112] = "Ô" + "&&" + "Ô" + "&&" + "Ô" $Codes[113] = "Õ" + "&&" + "Õ" + "&&" + "Õ" $Codes[114] = "Ö" + "&&" + "Ö" + "&&" + "Ö" $Codes[115] = "×" + "&&" + "×" + "&&" + "×" $Codes[116] = "Ø" + "&&" + "Ø" + "&&" + "Ø" $Codes[117] = "Ù" + "&&" + "Ù" + "&&" + "Ù" $Codes[118] = "Ú" + "&&" + "Ú" + "&&" + "Ú" $Codes[119] = "Û" + "&&" + "Û" + "&&" + "Û" $Codes[120] = "Ü" + "&&" + "Ü" + "&&" + "Ü" $Codes[121] = "Ý" + "&&" + "Ý" + "&&" + "Ý" $Codes[122] = "Þ" + "&&" + "Þ" + "&&" + "þ" $Codes[123] = "ß" + "&&" + "ß" + "&&" + "ß" $Codes[124] = "à" + "&&" + "à" + "&&" + "à" $Codes[125] = "á" + "&&" + "á" + "&&" + "á" $Codes[126] = "â" + "&&" + "â" + "&&" + "â" $Codes[127] = "ã" + "&&" + "ã" + "&&" + "ã" $Codes[128] = "ä" + "&&" + "ä" + "&&" + "ä" $Codes[129] = "å" + "&&" + "å" + "&&" + "å" $Codes[130] = "æ" + "&&" + "æ" + "&&" + "æ" $Codes[131] = "ç" + "&&" + "ç" + "&&" + "ç" $Codes[132] = "è" + "&&" + "è" + "&&" + "è" $Codes[133] = "é" + "&&" + "é" + "&&" + "é" $Codes[134] = "ê" + "&&" + "ê" + "&&" + "ê" $Codes[135] = "ë" + "&&" + "ë" + "&&" + "ë" $Codes[136] = "ì" + "&&" + "ì" + "&&" + "ì" $Codes[137] = "í" + "&&" + "í" + "&&" + "í" $Codes[138] = "î" + "&&" + "î" + "&&" + "î" $Codes[139] = "ï" + "&&" + "ï" + "&&" + "ï" $Codes[140] = "ð" + "&&" + "ð" + "&&" + "ð" $Codes[141] = "ñ" + "&&" + "ñ" + "&&" + "ñ" $Codes[142] = "ò" + "&&" + "ò" + "&&" + "ò" $Codes[143] = "ó" + "&&" + "ó" + "&&" + "ó" $Codes[144] = "ô" + "&&" + "ô" + "&&" + "ô" $Codes[145] = "õ" + "&&" + "õ" + "&&" + "õ" $Codes[146] = "ö" + "&&" + "ö" + "&&" + "ö" $Codes[147] = "÷" + "&&" + "÷" + "&&" + "÷" $Codes[148] = "ø" + "&&" + "ø" + "&&" + "ø" $Codes[149] = "ù" + "&&" + "ù" + "&&" + "ù" $Codes[150] = "ú" + "&&" + "ú" + "&&" + "ú" $Codes[151] = "û" + "&&" + "û" + "&&" + "û" $Codes[152] = "ü" + "&&" + "ü" + "&&" + "ü" $Codes[153] = "ý" + "&&" + "ý" + "&&" + "ý" $Codes[154] = "þ" + "&&" + "þ" + "&&" + "þ" $Codes[155] = "ÿ" + "&&" + "ÿ" + "&&" + "ÿ"
$MaxTries = LEN("$string") / 5 WHILE INSTR($string, "&") <> 0 AND $Tries < $MaxTries $Tries = $Tries + 1 $CodeFound = 0 $CodeStart = INSTR("$string", "&") $CodeEnd = INSTR("$string", ";") + 1 $CodeToReplace = SUBSTR("$string", $CodeStart, $CodeEnd - $CodeStart) $CodeLength = LEN("$CodeToReplace") ;---TEST ? "CodeStart: " + $CodeStart ? "CodeEnd: " + $CodeEnd ? "CodeToReplace: " + CHR(34) + $CodeToReplace + CHR(34) ? "CodeLength: " + $CodeLength ;---/TEST IF $CodeLength > 3 AND $CodeLength < 9 ;|All codes are between 4-8 characters long. $CodeAPos = ASCAN($Codes, $CodeToReplace) ? "CodeAPos: " + $CodeAPos IF NOT $CodePos < 0 ;|The code exists $CodeFound = 1 $CharToInsert = $Codes[$CodeAPos] ;---TEST ? "CharToInsert: " + $CharToInsert ;---/TEST $CharToInsert = SPLIT($CharToInsert, "&&")[0] ;---TEST ? "CharToInsert: " + $CharToInsert ;---/TEST $string = SUBSTR("$string", 1, $CodeStart - 1) + $CharToInsert + SUBSTR("$string", $CodeEnd, LEN("$string")) ENDIF ENDIF IF $CodeFound <> 1 ;|we need to skip the part which isn't convertible before the next loop $stringNoChar = $stringNoChar + SUBSTR("$string", 1, $CodeEnd) $string = SUBSTR("$string", $CodeEnd + 1, LEN("$string")) ENDIF LOOP $HTMLtoText = $string IF INSTR($HTMLtoText, "&#") <> 0 EXIT 3 ELSE EXIT 1 ENDIF ENDFUNCTION
[ 09. June 2003, 16:55: Message edited by: masken ]
_________________________
The tart is out there
|
|
Top
|
|
|
|
HTMLtoText, has anyone done that?
|
masken
|
2003-06-05 03:12 PM
|
Re: HTMLtoText, has anyone done that?
|
Kdyer
|
2003-06-05 04:38 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-05 04:51 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-05 06:16 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-06 08:15 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-06 10:23 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-07 12:14 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-06 01:01 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-06 01:26 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-06 03:27 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-06 03:40 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-06 03:42 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-07 10:35 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-07 10:24 PM
|
Re: HTMLtoText, has anyone done that?
|
Richard H.
|
2003-06-09 09:41 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-09 10:03 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-09 04:45 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-09 04:58 PM
|
Re: HTMLtoText, has anyone done that?
|
Richard H.
|
2003-06-09 05:13 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-09 05:17 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-09 06:26 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-09 06:28 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-09 10:49 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-09 11:08 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-09 11:29 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 10:14 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-10 10:35 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 11:16 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-10 11:48 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 11:51 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-10 11:55 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-11 12:15 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-11 12:22 AM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-11 12:27 AM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-10 01:29 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 01:33 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 01:34 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 01:49 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 01:56 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-10 02:26 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 03:38 PM
|
Re: HTMLtoText, has anyone done that?
|
masken
|
2003-06-10 03:42 PM
|
Re: HTMLtoText, has anyone done that?
|
Lonkero
|
2003-06-10 04:10 PM
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 765 anonymous users online.
|
|
|