Jump to content

HTML Entity UDF


Dhilip89
 Share

Recommended Posts

Hello, I just made an UDF for Encoding/Decoding the string and HTML Entity Number.

HTML.au3:

#include-once
#include <Array.au3>

Dim $Entity[65536]
$Entity[34] = "quot"
$Entity[38] = "amp"
$Entity[39] = "apos"
$Entity[60] = "lt"
$Entity[62] = "gt"
$Entity[160] = "nbsp"
$Entity[161] = "iexcl"
$Entity[162] = "cent"
$Entity[163] = "pound"
$Entity[164] = "curren"
$Entity[165] = "yen"
$Entity[166] = "brvbar"
$Entity[167] = "sect"
$Entity[168] = "uml"
$Entity[169] = "copy"
$Entity[170] = "ordf"
$Entity[171] = "laquo"
$Entity[172] = "not"
$Entity[173] = "shy"
$Entity[174] = "reg"
$Entity[175] = "macr"
$Entity[176] = "deg"
$Entity[177] = "plusmn"
$Entity[178] = "sup2"
$Entity[179] = "sup3"
$Entity[180] = "acute"
$Entity[181] = "micro"
$Entity[182] = "para"
$Entity[183] = "middot"
$Entity[184] = "cedil"
$Entity[185] = "sup1"
$Entity[186] = "ordm"
$Entity[187] = "raquo"
$Entity[188] = "frac14"
$Entity[189] = "frac12"
$Entity[190] = "frac34"
$Entity[191] = "iquest"
$Entity[192] = "Agrave"
$Entity[193] = "Aacute"
$Entity[194] = "Acirc"
$Entity[195] = "Atilde"
$Entity[196] = "Auml"
$Entity[197] = "Aring"
$Entity[198] = "AElig"
$Entity[199] = "Ccedil"
$Entity[200] = "Egrave"
$Entity[201] = "Eacute"
$Entity[202] = "Ecirc"
$Entity[203] = "Euml"
$Entity[204] = "Igrave"
$Entity[205] = "Iacute"
$Entity[206] = "Icirc"
$Entity[207] = "Iuml"
$Entity[208] = "ETH"
$Entity[209] = "Ntilde"
$Entity[210] = "Ograve"
$Entity[211] = "Oacute"
$Entity[212] = "Ocirc"
$Entity[213] = "Otilde"
$Entity[214] = "Ouml"
$Entity[215] = "times"
$Entity[216] = "Oslash"
$Entity[217] = "Ugrave"
$Entity[218] = "Uacute"
$Entity[219] = "Ucirc"
$Entity[220] = "Uuml"
$Entity[221] = "Yacute"
$Entity[222] = "THORN"
$Entity[223] = "szlig"
$Entity[224] = "agrave"
$Entity[225] = "aacute"
$Entity[226] = "acirc"
$Entity[227] = "atilde"
$Entity[228] = "auml"
$Entity[229] = "aring"
$Entity[230] = "aelig"
$Entity[231] = "ccedil"
$Entity[232] = "egrave"
$Entity[233] = "eacute"
$Entity[234] = "ecirc"
$Entity[235] = "euml"
$Entity[236] = "igrave"
$Entity[237] = "iacute"
$Entity[238] = "icirc"
$Entity[239] = "iuml"
$Entity[240] = "eth"
$Entity[241] = "ntilde"
$Entity[242] = "ograve"
$Entity[243] = "oacute"
$Entity[244] = "ocirc"
$Entity[245] = "otilde"
$Entity[246] = "ouml"
$Entity[247] = "divide"
$Entity[248] = "oslash"
$Entity[249] = "ugrave"
$Entity[250] = "uacute"
$Entity[251] = "ucirc"
$Entity[252] = "uuml"
$Entity[253] = "yacute"
$Entity[254] = "thorn"
$Entity[255] = "yuml"
$Entity[338] = "OElig"
$Entity[339] = "oelig"
$Entity[352] = "Scaron"
$Entity[353] = "scaron"
$Entity[376] = "Yuml"
$Entity[402] = "fnof"
$Entity[710] = "circ"
$Entity[732] = "tilde"
$Entity[913] = "Alpha"
$Entity[914] = "Beta"
$Entity[915] = "Gamma"
$Entity[916] = "Delta"
$Entity[917] = "Epsilon"
$Entity[918] = "Zeta"
$Entity[919] = "Eta"
$Entity[920] = "Theta"
$Entity[921] = "Iota"
$Entity[922] = "Kappa"
$Entity[923] = "Lambda"
$Entity[924] = "Mu"
$Entity[925] = "Nu"
$Entity[926] = "Xi"
$Entity[927] = "Omicron"
$Entity[928] = "Pi"
$Entity[929] = "Rho"
$Entity[931] = "Sigma"
$Entity[932] = "Tau"
$Entity[933] = "Upsilon"
$Entity[934] = "Phi"
$Entity[935] = "Chi"
$Entity[936] = "Psi"
$Entity[937] = "Omega"
$Entity[945] = "alpha"
$Entity[946] = "beta"
$Entity[947] = "gamma"
$Entity[948] = "delta"
$Entity[949] = "epsilon"
$Entity[950] = "zeta"
$Entity[951] = "eta"
$Entity[952] = "theta"
$Entity[953] = "iota"
$Entity[954] = "kappa"
$Entity[955] = "lambda"
$Entity[956] = "mu"
$Entity[957] = "nu"
$Entity[958] = "xi"
$Entity[959] = "omicron"
$Entity[960] = "pi"
$Entity[961] = "rho"
$Entity[962] = "sigmaf"
$Entity[963] = "sigma"
$Entity[964] = "tau"
$Entity[965] = "upsilon"
$Entity[966] = "phi"
$Entity[967] = "chi"
$Entity[968] = "psi"
$Entity[969] = "omega"
$Entity[977] = "thetasym"
$Entity[978] = "upsih"
$Entity[982] = "piv"
$Entity[8194] = "ensp"
$Entity[8195] = "emsp"
$Entity[8201] = "thinsp"
$Entity[8204] = "zwnj"
$Entity[8205] = "zwj"
$Entity[8206] = "lrm"
$Entity[8207] = "rlm"
$Entity[8211] = "ndash"
$Entity[8212] = "mdash"
$Entity[8216] = "lsquo"
$Entity[8217] = "rsquo"
$Entity[8218] = "sbquo"
$Entity[8220] = "ldquo"
$Entity[8221] = "rdquo"
$Entity[8222] = "bdquo"
$Entity[8224] = "dagger"
$Entity[8225] = "Dagger"
$Entity[8226] = "bull"
$Entity[8230] = "hellip"
$Entity[8240] = "permil"
$Entity[8242] = "prime"
$Entity[8243] = "Prime"
$Entity[8249] = "lsaquo"
$Entity[8250] = "rsaquo"
$Entity[8254] = "oline"
$Entity[8260] = "frasl"
$Entity[8364] = "euro"
$Entity[8465] = "image"
$Entity[8472] = "weierp"
$Entity[8476] = "real"
$Entity[8482] = "trade"
$Entity[8501] = "alefsym"
$Entity[8592] = "larr"
$Entity[8593] = "uarr"
$Entity[8594] = "rarr"
$Entity[8595] = "darr"
$Entity[8596] = "harr"
$Entity[8629] = "crarr"
$Entity[8656] = "lArr"
$Entity[8657] = "uArr"
$Entity[8658] = "rArr"
$Entity[8659] = "dArr"
$Entity[8660] = "hArr"
$Entity[8704] = "forall"
$Entity[8706] = "part"
$Entity[8707] = "exist"
$Entity[8709] = "empty"
$Entity[8711] = "nabla"
$Entity[8712] = "isin"
$Entity[8713] = "notin"
$Entity[8715] = "ni"
$Entity[8719] = "prod"
$Entity[8721] = "sum"
$Entity[8722] = "minus"
$Entity[8727] = "lowast"
$Entity[8730] = "radic"
$Entity[8733] = "prop"
$Entity[8734] = "infin"
$Entity[8736] = "ang"
$Entity[8743] = "and"
$Entity[8744] = "or"
$Entity[8745] = "cap"
$Entity[8746] = "cup"
$Entity[8747] = "int"
$Entity[8756] = "there4"
$Entity[8764] = "sim"
$Entity[8773] = "cong"
$Entity[8776] = "asymp"
$Entity[8800] = "ne"
$Entity[8801] = "equiv"
$Entity[8804] = "le"
$Entity[8805] = "ge"
$Entity[8834] = "sub"
$Entity[8835] = "sup"
$Entity[8836] = "nsub"
$Entity[8838] = "sube"
$Entity[8839] = "supe"
$Entity[8853] = "oplus"
$Entity[8855] = "otimes"
$Entity[8869] = "perp"
$Entity[8901] = "sdot"
$Entity[8968] = "lceil"
$Entity[8969] = "rceil"
$Entity[8970] = "lfloor"
$Entity[8971] = "rfloor"
$Entity[9001] = "lang"
$Entity[9002] = "rang"
$Entity[9674] = "loz"
$Entity[9824] = "spades"
$Entity[9827] = "clubs"
$Entity[9829] = "hearts"
$Entity[9830] = "diams"

;===============================================================================
;
; Function Name:    _HTMLEncode()
; Description:      Encode the normal string into HTML Entity Number
; Parameter(s):     $String     - The string you want to encode.
;
; Requirement(s):   AutoIt v3.2.4.9 or higher (Unicode)
; Return Value(s):  On Success  - Returns HTML Entity Number
;                   On Failure  - Nothing
;
; Author(s):        Dhilip89
;
;===============================================================================


Func _HTMLEncode($Str)
    $StrLen = StringLen($Str)
    Local $Encoded
    If $StrLen = 0 Then Return ''
    For $i = 1 To $StrLen
        $StrChar = StringMid($Str, $i, 1)
        $Encoded &= '&#' & AscW($StrChar) & ';'
    Next
    Return $Encoded
EndFunc   ;==>_HTMLEncode


;===============================================================================
;
; Function Name:    _HTMLDecode()
; Description:      Decode the HTML Entity Number into normal string
; Parameter(s):     $HTMLEntityNum  - The HTML Entity Number you want to decode.
;
; Requirement(s):   AutoIt v3.2.4.9 or higher (Unicode)
; Return Value(s):  On Success  - Returns decoded strings
;                   On Failure  - Nothing
;
; Author(s):        Dhilip89
;
;===============================================================================

Func _HTMLDecode($Str)
    Local $Decoded
    If $Str = '' Then Return ''
    $X1 = StringRegExp($Str, '&#x(.*?);', 3)
    $X2 = StringRegExp($Str, '&#(.*?);', 3)
    $X3 = StringRegExp($Str, '&(.*?);', 3)
    For $i = 0 To UBound($X1) - 1 Step 1
        $Str = StringReplace($Str, '&#x' & $X1[$i] & ';', ChrW(Dec($X1[$i])))
    Next
    For $i = 0 To UBound($X2) - 1 Step 1
        $Str = StringReplace($Str, '&#' & $X2[$i] & ';', ChrW($X2[$i]))
    Next
    For $i = 0 To UBound($X3) - 1 Step 1
        $Str = StringReplace($Str, '&' & $X3[$i] & ';', ChrW(_ArraySearch($Entity, $X3[$i], 0, 0, 1)))
    Next
    $Decoded = $Str
    Return $Decoded
EndFunc   ;==>_HTMLDecode

Download: HTML.au3

Edited by Dhilip89

[u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]

Link to comment
Share on other sites

  • 2 weeks later...

Really nobody want reply to this topic ? :)

Edited by Dhilip

[u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]

Link to comment
Share on other sites

  • 1 year later...

I'd be more interested in something that handles named entities like &rdquo; for example.

WBD

Link to comment
Share on other sites

  • 3 months later...

Well... that's pretty lame but it gets the job done...

fixed my issues with them entities.

#include "__HTMLSpecials.au3" :

_____________________________ :

Dim $HTML_SpecialChars[101][2]
$HTML_SpecialChars[0][0] = '&amp;'
$HTML_SpecialChars[0][1] = 38
$HTML_SpecialChars[1][0] = '&nbsp;'
$HTML_SpecialChars[1][1] = 160
$HTML_SpecialChars[2][0] = '&iexcl;'
$HTML_SpecialChars[2][1] = 161
$HTML_SpecialChars[3][0] = '&cent;'
$HTML_SpecialChars[3][1] = 162
$HTML_SpecialChars[4][0] = '&pound;'
$HTML_SpecialChars[4][1] = 163
$HTML_SpecialChars[5][0] = '&curren;'
$HTML_SpecialChars[5][1] = 164
$HTML_SpecialChars[6][0] = '&yen;'
$HTML_SpecialChars[6][1] = 165
$HTML_SpecialChars[7][0] = '&brvbar;'
$HTML_SpecialChars[7][1] = 166
$HTML_SpecialChars[8][0] = '&sect;'
$HTML_SpecialChars[8][1] = 167
$HTML_SpecialChars[9][0] = '&uml;'
$HTML_SpecialChars[9][1] = 168
$HTML_SpecialChars[10][0] = '&copy;'
$HTML_SpecialChars[10][1] = 169
$HTML_SpecialChars[11][0] = '&ordf;'
$HTML_SpecialChars[11][1] = 170
$HTML_SpecialChars[12][0] = '&laquo;'
$HTML_SpecialChars[12][1] = 171
$HTML_SpecialChars[13][0] = '&not;'
$HTML_SpecialChars[13][1] = 172
$HTML_SpecialChars[14][0] = '&shy;'
$HTML_SpecialChars[14][1] = 173
$HTML_SpecialChars[15][0] = '&reg;'
$HTML_SpecialChars[15][1] = 174
$HTML_SpecialChars[16][0] = '&macr;'
$HTML_SpecialChars[16][1] = 175
$HTML_SpecialChars[17][0] = '&deg;'
$HTML_SpecialChars[17][1] = 176
$HTML_SpecialChars[18][0] = '&plusmn;'
$HTML_SpecialChars[18][1] = 177
$HTML_SpecialChars[19][0] = '&sup2;'
$HTML_SpecialChars[19][1] = 178
$HTML_SpecialChars[20][0] = '&sup3;'
$HTML_SpecialChars[20][1] = 179
$HTML_SpecialChars[21][0] = '&acute;'
$HTML_SpecialChars[21][1] = 180
$HTML_SpecialChars[22][0] = '&micro;'
$HTML_SpecialChars[22][1] = 181
$HTML_SpecialChars[23][0] = '&para;'
$HTML_SpecialChars[23][1] = 182
$HTML_SpecialChars[24][0] = '&middot;'
$HTML_SpecialChars[24][1] = 183
$HTML_SpecialChars[25][0] = '&cedil;'
$HTML_SpecialChars[25][1] = 184
$HTML_SpecialChars[26][0] = '&sup1;'
$HTML_SpecialChars[26][1] = 185
$HTML_SpecialChars[27][0] = '&ordm;'
$HTML_SpecialChars[27][1] = 186
$HTML_SpecialChars[28][0] = '&raquo;'
$HTML_SpecialChars[28][1] = 187
$HTML_SpecialChars[29][0] = '&frac14;'
$HTML_SpecialChars[29][1] = 188
$HTML_SpecialChars[30][0] = '&frac12;'
$HTML_SpecialChars[30][1] = 189
$HTML_SpecialChars[31][0] = '&frac34;'
$HTML_SpecialChars[31][1] = 190
$HTML_SpecialChars[32][0] = '&iquest;'
$HTML_SpecialChars[32][1] = 191
$HTML_SpecialChars[33][0] = '&Agrave;'
$HTML_SpecialChars[33][1] = 192
$HTML_SpecialChars[34][0] = '&Aacute;'
$HTML_SpecialChars[34][1] = 193
$HTML_SpecialChars[35][0] = '&Acirc;'
$HTML_SpecialChars[35][1] = 194
$HTML_SpecialChars[36][0] = '&Atilde;'
$HTML_SpecialChars[36][1] = 195
$HTML_SpecialChars[37][0] = '&Auml;'
$HTML_SpecialChars[37][1] = 196
$HTML_SpecialChars[38][0] = '&Aring;'
$HTML_SpecialChars[38][1] = 197
$HTML_SpecialChars[39][0] = '&AElig;'
$HTML_SpecialChars[39][1] = 198
$HTML_SpecialChars[40][0] = '&Ccedil;'
$HTML_SpecialChars[40][1] = 199
$HTML_SpecialChars[41][0] = '&Egrave;'
$HTML_SpecialChars[41][1] = 200
$HTML_SpecialChars[42][0] = '&Eacute;'
$HTML_SpecialChars[42][1] = 201
$HTML_SpecialChars[43][0] = '&Ecirc;'
$HTML_SpecialChars[43][1] = 202
$HTML_SpecialChars[44][0] = '&Euml;'
$HTML_SpecialChars[44][1] = 203
$HTML_SpecialChars[45][0] = '&Igrave;'
$HTML_SpecialChars[45][1] = 204
$HTML_SpecialChars[46][0] = '&Iacute;'
$HTML_SpecialChars[46][1] = 205
$HTML_SpecialChars[47][0] = '&Icirc;'
$HTML_SpecialChars[47][1] = 206
$HTML_SpecialChars[48][0] = '&Iuml;'
$HTML_SpecialChars[48][1] = 207
$HTML_SpecialChars[49][0] = '&ETH;'
$HTML_SpecialChars[49][1] = 208
$HTML_SpecialChars[50][0] = '&Ntilde;'
$HTML_SpecialChars[50][1] = 209
$HTML_SpecialChars[51][0] = '&Ograve;'
$HTML_SpecialChars[51][1] = 210
$HTML_SpecialChars[52][0] = '&Oacute;'
$HTML_SpecialChars[52][1] = 211
$HTML_SpecialChars[53][0] = '&Ocirc;'
$HTML_SpecialChars[53][1] = 212
$HTML_SpecialChars[54][0] = '&Otilde;'
$HTML_SpecialChars[54][1] = 213
$HTML_SpecialChars[55][0] = '&Ouml;'
$HTML_SpecialChars[55][1] = 214
$HTML_SpecialChars[56][0] = '&times;'
$HTML_SpecialChars[56][1] = 215
$HTML_SpecialChars[57][0] = '&Oslash;'
$HTML_SpecialChars[57][1] = 216
$HTML_SpecialChars[58][0] = '&Ugrave;'
$HTML_SpecialChars[58][1] = 217
$HTML_SpecialChars[59][0] = '&Uacute;'
$HTML_SpecialChars[59][1] = 218
$HTML_SpecialChars[60][0] = '&Ucirc;'
$HTML_SpecialChars[60][1] = 219
$HTML_SpecialChars[61][0] = '&Uuml;'
$HTML_SpecialChars[61][1] = 220
$HTML_SpecialChars[62][0] = '&Yacute;'
$HTML_SpecialChars[62][1] = 221
$HTML_SpecialChars[63][0] = '&THORN;'
$HTML_SpecialChars[63][1] = 222
$HTML_SpecialChars[64][0] = '&szlig;'
$HTML_SpecialChars[64][1] = 223
$HTML_SpecialChars[65][0] = '&agrave;'
$HTML_SpecialChars[65][1] = 224
$HTML_SpecialChars[66][0] = '&aacute;'
$HTML_SpecialChars[66][1] = 225
$HTML_SpecialChars[67][0] = '&acirc;'
$HTML_SpecialChars[67][1] = 226
$HTML_SpecialChars[68][0] = '&atilde;'
$HTML_SpecialChars[68][1] = 227
$HTML_SpecialChars[69][0] = '&auml;'
$HTML_SpecialChars[69][1] = 228
$HTML_SpecialChars[70][0] = '&aring;'
$HTML_SpecialChars[70][1] = 229
$HTML_SpecialChars[71][0] = '&aelig;'
$HTML_SpecialChars[71][1] = 230
$HTML_SpecialChars[72][0] = '&ccedil;'
$HTML_SpecialChars[72][1] = 231
$HTML_SpecialChars[73][0] = '&egrave;'
$HTML_SpecialChars[73][1] = 232
$HTML_SpecialChars[74][0] = '&eacute;'
$HTML_SpecialChars[74][1] = 233
$HTML_SpecialChars[75][0] = '&ecirc;'
$HTML_SpecialChars[75][1] = 234
$HTML_SpecialChars[76][0] = '&euml;'
$HTML_SpecialChars[76][1] = 235
$HTML_SpecialChars[77][0] = '&igrave;'
$HTML_SpecialChars[77][1] = 236
$HTML_SpecialChars[78][0] = '&iacute;'
$HTML_SpecialChars[78][1] = 237
$HTML_SpecialChars[79][0] = '&icirc;'
$HTML_SpecialChars[79][1] = 238
$HTML_SpecialChars[80][0] = '&iuml;'
$HTML_SpecialChars[80][1] = 239
$HTML_SpecialChars[81][0] = '&eth;'
$HTML_SpecialChars[81][1] = 240
$HTML_SpecialChars[82][0] = '&ntilde;'
$HTML_SpecialChars[82][1] = 241
$HTML_SpecialChars[83][0] = '&ograve;'
$HTML_SpecialChars[83][1] = 242
$HTML_SpecialChars[84][0] = '&oacute;'
$HTML_SpecialChars[84][1] = 243
$HTML_SpecialChars[85][0] = '&ocirc;'
$HTML_SpecialChars[85][1] = 244
$HTML_SpecialChars[86][0] = '&otilde;'
$HTML_SpecialChars[86][1] = 245
$HTML_SpecialChars[87][0] = '&ouml;'
$HTML_SpecialChars[87][1] = 246
$HTML_SpecialChars[88][0] = '&divide;'
$HTML_SpecialChars[88][1] = 247
$HTML_SpecialChars[89][0] = '&oslash;'
$HTML_SpecialChars[89][1] = 248
$HTML_SpecialChars[90][0] = '&ugrave;'
$HTML_SpecialChars[90][1] = 249
$HTML_SpecialChars[91][0] = '&uacute;'
$HTML_SpecialChars[91][1] = 250
$HTML_SpecialChars[92][0] = '&ucirc;'
$HTML_SpecialChars[92][1] = 251
$HTML_SpecialChars[93][0] = '&uuml;'
$HTML_SpecialChars[93][1] = 252
$HTML_SpecialChars[94][0] = '&yacute;'
$HTML_SpecialChars[94][1] = 253
$HTML_SpecialChars[95][0] = '&thorn;'
$HTML_SpecialChars[95][1] = 254
$HTML_SpecialChars[96][0] = '&yuml;'
$HTML_SpecialChars[96][1] = 255
$HTML_SpecialChars[97][0] = '&quot;'
$HTML_SpecialChars[97][1] = 34
$HTML_SpecialChars[98][0] = '''
$HTML_SpecialChars[98][1] = 39
$HTML_SpecialChars[99][0] = '&lt;'
$HTML_SpecialChars[99][1] = 60
$HTML_SpecialChars[100][0] = '&gt;'
$HTML_SpecialChars[100][1] = 62

_HTMLEntityNumDecode() :

_______________________:

;===============================================================================
;
; Function Name:    _HTMLEntityNumDecode()
; Description:      Decode the HTML Entities from a text into normal string.
; Parameter(s):     $Text   - Whatever text you want to decode.
;
; Requirement(s):   AutoIt v3.2.4.9 or higher (Unicode)
; Return Value(s):  On Success  - Returns decoded text
;                   On Failure  - Nothing
;
; Author(s):        Dhilip89, Modified by SK
;
;===============================================================================
Func _HTMLEntityNumDecode($Text)
    ;ConsoleWrite("+ _HTMLEntityNumDecode() Decoding:: "&@CRLF&$Text&@CRLF)
    $ReformatedStr = ""
    $StrExp = StringRegExp($Text, "([\s\S]*?)&#(x?\d+);([\s\S]*)", 3) ;Gives you the TEXT [Entity] TEXT
    If @error = 0 Then
        While 1
            ;First part isn't an entity - just add it...
            $ReformatedStr &= $StrExp[0]

            ;Second part must be an entity [if present]
            If StringLeft($StrExp[1], 1) = "x" Then
                ;Check for Dec/Hex variations... HEX is with x.
                $strHex = StringTrimLeft($StrExp[1], 1)
                $ReformatedStr &= ChrW(Dec($strHex))
            Else
                $ReformatedStr &= ChrW($StrExp[1])
            EndIf

            ;Look for more entities...
            $Text = $StrExp[2];
            $StrExp = StringRegExp($Text, "([\s\S]*?)&#(x?\d+);([\s\S]*)", 3) ;Gives you the TEXT [Entity] TEXT
            If @error <> 0 Then ExitLoop
        WEnd
    EndIf
    ;If we had an entity to decode, add the left overs! Else -> return the entire text.
    $ReformatedStr &= $Text

    $ret = StringRegExp($ReformatedStr, '(&.+;)', 3)
    If @error = 0 Then
        ;We have some specials!
        #include "__HTMLSpecials.au3"
        For $i = 0 To UBound($ret)-1
            $id = _ArraySearch($HTML_SpecialChars, $ret[$i])
            If $id <> -1 Then
                $ReformatedStr = StringReplace($ReformatedStr, $ret[$i], ChrW($HTML_SpecialChars[$id][1]))
                If @extended = 0 Then
                    ;ConsoleWrite("Can't convert the entity: "&$ret[$i]&@CRLF)
                Else
                    ;ConsoleWrite("Switched: "&$ret[$i]& " With: "& ChrW($HTML_SpecialChars[$id][1]) & @CRLF)
                EndIf
            Else
                ;ConsoleWrite("Couldn't find the resolution in $HTML_SpecialChars"&@CRLF)
            EndIf
        Next
    Else
        ;ConsoleWrite("No Special-Entities"&@CRLF)
    EndIf

    ;Dump the array
    $HTML_SpecialChars = ""

    ;We are done -> send the new string. [Only entities!]
    ;ConsoleWrite("- _HTMLEntityNumDecode() Returning:: "&@CRLF&$ReformatedStr&@CRLF)
    Return $ReformatedStr
EndFunc   ;==>_HTMLEntityNumDecode

I'm '#include "__HTMLSpecials.au3"' since maybe we don't have to load that huge array.

:D

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Link to comment
Share on other sites

Update: replaced obsolete script with better script found in my backup. :D

[u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]

Link to comment
Share on other sites

  • 2 years later...
  • 6 years later...

Use this:

Local $s = " Chung V&#7847;ng Tr&#259;ng &#272;&#7907;i ", $t
$t = Execute("'" & StringRegExpReplace($s, "(&#)(\d+)(;)", "' & ChrW($2) & '") & "'")
MsgBox(0, "", $t)

 

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...