#101880 - 2003-06-06 01:01 PM
Re: HTMLtoText, has anyone done that?
|
masken
MM club member
   
Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
|
Ok, this works, with some limitations. Please comment:
code:
;FUNCTION HTMLtoText() ; ;ACTION Convert a HTML source string into plain text ; ;AUTHOR masken (masken|at|home.se) ; ;VERSION 1.0 ; ;DATE CREATED 2003-06-06 ; ;DATE MODIFIED - ; ;KIXTART 4.12+ ; ;SYNTAX HTMLtoText([STRING]) ; ;PARAMETERS STRING ; The string you want to convert. ; ;RETURNS 1 If all HTML codes were converted ; 2 If there were no codes to convert ; 3 If not all codes could be converted ; ;REMARKS * If there's a ";" in the $STRING (ie; the HTML source), ; the conversion will go wrong (there shouldn't be any though). ; * Only handles decimal codes. Some webpage code might have hex codes. ; * Doesn't handle alternatives, like """ and " " for example. ; ; The list of decimal codes used for the arrays were taken from here: ; http://tergestesoft.com/~eddysworld/spechars.htm ; ;DEPENDENCIES none ; ;EXAMPLE $htmlstring = "Implacável" ; $result = HTMLtoText($htmlstring) ; ; $result will be: "Implacável" ; ;KIXTART BBS http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=14&t=000765 ; ;===============================================================================
Function HTMLtoText($string) ;| Exit if there's nothing to convert IF INSTR($string, "&#") = 0 EXIT 2 ENDIF
DIM $Code[157] $Code[0] = "	" $Code[1] = " " $Code[2] = " " $Code[3] = " " $Code[4] = "!" $Code[5] = """ $Code[6] = "#" $Code[7] = "$" $Code[8] = "%" $Code[9] = "&" $Code[10] = "'" $Code[11] = "(" $Code[12] = ")" $Code[13] = "*" $Code[14] = "+" $Code[15] = "," $Code[16] = "-" $Code[17] = "." $Code[18] = "/" $Code[19] = ":" $Code[20] = ";" $Code[21] = "<" $Code[22] = "=" $Code[23] = ">" $Code[24] = "?" $Code[25] = "@" $Code[26] = "[" $Code[27] = "\" $Code[28] = "]" $Code[29] = "^" $Code[30] = "_" $Code[31] = "`" $Code[32] = "{" $Code[33] = "|" $Code[34] = "}" $Code[35] = "~" $Code[36] = "‚" $Code[37] = "ƒ" $Code[38] = "„" $Code[39] = "…" $Code[40] = "†" $Code[41] = "‡" $Code[42] = "ˆ" $Code[43] = "‰" $Code[44] = "Š" $Code[45] = "‹" $Code[46] = "Œ" $Code[47] = "‘" $Code[48] = "’" $Code[49] = "“" $Code[50] = "”" $Code[51] = "•" $Code[52] = "–" $Code[53] = "—" $Code[54] = "˜" $Code[55] = "™" $Code[56] = "š" $Code[57] = "›" $Code[58] = "œ" $Code[59] = "Ÿ" $Code[60] = " " $Code[61] = "¡" $Code[62] = "¢" $Code[63] = "£" $Code[64] = "¤" $Code[65] = "¥" $Code[66] = "¦" $Code[67] = "§" $Code[68] = "¨" $Code[69] = "©" $Code[70] = "ª" $Code[71] = "«" $Code[72] = "¬" $Code[73] = "­" $Code[74] = "®" $Code[75] = "¯" $Code[76] = "°" $Code[77] = "±" $Code[78] = "²" $Code[79] = "³" $Code[80] = "´" $Code[81] = "µ" $Code[82] = "¶" $Code[83] = "·" $Code[84] = "¸" $Code[85] = "¹" $Code[86] = "º" $Code[87] = "»" $Code[88] = "¼" $Code[89] = "½" $Code[90] = "¾" $Code[91] = "¿" $Code[92] = "À" $Code[93] = "Á" $Code[94] = "Â" $Code[95] = "Ã" $Code[96] = "Ä" $Code[97] = "Å" $Code[98] = "Æ" $Code[99] = "Ç" $Code[100] = "È" $Code[101] = "É" $Code[102] = "Ê" $Code[103] = "Ë" $Code[104] = "Ì" $Code[105] = "Í" $Code[106] = "Î" $Code[107] = "Ï" $Code[108] = "Ð" $Code[109] = "Ñ" $Code[110] = "Ò" $Code[111] = "Ó" $Code[112] = "Ô" $Code[113] = "Õ" $Code[114] = "Ö" $Code[115] = "×" $Code[116] = "Ø" $Code[117] = "Ù" $Code[118] = "Ú" $Code[119] = "Û" $Code[120] = "Ü" $Code[121] = "Ý" $Code[122] = "Þ" $Code[123] = "ß" $Code[124] = "à" $Code[125] = "á" $Code[126] = "â" $Code[127] = "ã" $Code[128] = "ä" $Code[129] = "å" $Code[130] = "æ" $Code[131] = "ç" $Code[132] = "è" $Code[133] = "é" $Code[134] = "ê" $Code[135] = "ë" $Code[136] = "ì" $Code[137] = "í" $Code[138] = "î" $Code[139] = "ï" $Code[140] = "ð" $Code[141] = "ñ" $Code[142] = "ò" $Code[143] = "ó" $Code[144] = "ô" $Code[145] = "õ" $Code[146] = "ö" $Code[147] = "÷" $Code[148] = "ø" $Code[149] = "ù" $Code[150] = "ú" $Code[151] = "û" $Code[152] = "ü" $Code[153] = "ý" $Code[154] = "þ" $Code[155] = "ÿ"
DIM $Char[157] $Char[0] = CHR(9) $Char[1] = CHR(10) $Char[2] = CHR(13) $Char[3] = " " $Char[4] = "!" $Char[5] = CHR(34) $Char[6] = "#" $Char[7] = CHR(36) $Char[8] = "%" $Char[9] = "&" $Char[10] = CHR(39) $Char[11] = "(" $Char[12] = ")" $Char[13] = "*" $Char[14] = "+" $Char[15] = "," $Char[16] = "-" $Char[17] = "." $Char[18] = "/" $Char[19] = ":" $Char[20] = ";" $Char[21] = "<" $Char[22] = "=" $Char[23] = ">" $Char[24] = "?" $Char[25] = "@" $Char[26] = "[" $Char[27] = "\" $Char[28] = "]" $Char[29] = "^" $Char[30] = "_" $Char[31] = "`" $Char[32] = "{" $Char[33] = "|" $Char[34] = "}" $Char[35] = "~" $Char[36] = "‚" $Char[37] = "ƒ" $Char[38] = "„" $Char[39] = "…" $Char[40] = "†" $Char[41] = "‡" $Char[42] = "ˆ" $Char[43] = "‰" $Char[44] = "Š" $Char[45] = "‹" $Char[46] = "Œ" $Char[47] = "‘" $Char[48] = "’" $Char[49] = "“" $Char[50] = "”" $Char[51] = "•" $Char[52] = "–" $Char[53] = "—" $Char[54] = "˜" $Char[55] = "™" $Char[56] = "š" $Char[57] = "›" $Char[58] = "œ" $Char[59] = "Ÿ" $Char[60] = " " $Char[61] = "¡" $Char[62] = "¢" $Char[63] = "£" $Char[64] = "¤" $Char[65] = "¥" $Char[66] = "¦" $Char[67] = "§" $Char[68] = "¨" $Char[69] = "©" $Char[70] = "ª" $Char[71] = "«" $Char[72] = "¬" $Char[73] = "" $Char[74] = "®" $Char[75] = "¯" $Char[76] = "°" $Char[77] = "±" $Char[78] = "²" $Char[79] = "³" $Char[80] = "´" $Char[81] = "µ" $Char[82] = "¶" $Char[83] = "·" $Char[84] = "¸" $Char[85] = "¹" $Char[86] = "º" $Char[87] = "»" $Char[88] = "¼" $Char[89] = "½" $Char[90] = "¾" $Char[91] = "¿" $Char[92] = "À" $Char[93] = "Á" $Char[94] = "Â" $Char[95] = "Ã" $Char[96] = "Ä" $Char[97] = "Å" $Char[98] = "Æ" $Char[99] = "Ç" $Char[100] = "È" $Char[101] = "É" $Char[102] = "Ê" $Char[103] = "Ë" $Char[104] = "Ì" $Char[105] = "Í" $Char[106] = "Î" $Char[107] = "Ï" $Char[108] = "Ð" $Char[109] = "Ñ" $Char[110] = "Ò" $Char[111] = "Ó" $Char[112] = "Ô" $Char[113] = "Õ" $Char[114] = "Ö" $Char[115] = "×" $Char[116] = "Ø" $Char[117] = "Ù" $Char[118] = "Ú" $Char[119] = "Û" $Char[120] = "Ü" $Char[121] = "Ý" $Char[122] = "Þ" $Char[123] = "ß" $Char[124] = "à" $Char[125] = "á" $Char[126] = "â" $Char[127] = "ã" $Char[128] = "ä" $Char[129] = "å" $Char[130] = "æ" $Char[131] = "ç" $Char[132] = "è" $Char[133] = "é" $Char[134] = "ê" $Char[135] = "ë" $Char[136] = "ì" $Char[137] = "í" $Char[138] = "î" $Char[139] = "ï" $Char[140] = "ð" $Char[141] = "ñ" $Char[142] = "ò" $Char[143] = "ó" $Char[144] = "ô" $Char[145] = "õ" $Char[146] = "ö" $Char[147] = "÷" $Char[148] = "ø" $Char[149] = "ù" $Char[150] = "ú" $Char[151] = "û" $Char[152] = "ü" $Char[153] = "ý" $Char[154] = "þ" $Char[155] = "ÿ"
$MaxTries = LEN("$string") / 5 WHILE INSTR($string, "&#") <> 0 AND $Tries < $MaxTries $Tries = $Tries + 1 $CodeStart = INSTR("$string", "&#") $CodeEnd = INSTR("$string", ";") + 1 $CodeToReplace = SUBSTR("$string", $CodeStart, $CodeEnd - $CodeStart) $CodeAPos = ASCAN($Code, $CodeToReplace) IF $CodePos <> -1 $CharToInsert = $Char[$CodeAPos] $string = SUBSTR("$string", 1, $CodeStart - 1) + $CharToInsert + SUBSTR("$string", $CodeEnd, LEN("$string")) ENDIF LOOP $HTMLtoText = $string IF INSTR($HTMLtoText, "&#") <> 0 EXIT 3 ELSE EXIT 1 ENDIF EndFunction
[ 06. June 2003, 13:07: 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 988 anonymous users online.
|
|
|