Что нового

Перекодирование мнемоник HTML в символы

inververs

AutoIT Гуру
Сообщения
2,135
Репутация
465
Как перекодировать мнемоники в HTML в символы?
http://ru.wikipedia.org/wiki/Мнемоники_в_HTML

Есть ли готовые методы или свойства каких нибудь объектов - позволяющие это делать.
Уж очень не хочеться преобразовывать через StringReplace.
 

AZJIO

Меценат
Меценат
Сообщения
2,892
Репутация
1,196
inververs
Вот мои пробы

Код:
$OpenFile = FileOpenDialog('Открыть', @WorkingDir , "веб-страница (*.htm*)")
If @error Then Exit

$file = FileOpen($OpenFile, 0)
$text = FileRead($file)
FileClose($file)

;http://www.shtogrin.com/library/web/pcre/examples/convert_html2txt/
; в чётных строках текст поиска, в нечётных текст замены
Dim $search[27] = [26, _
'<script[^>]*?>.*?</script>', _
'', _
'<[\/\!]*?[^<>]*?>', _
@CRLF, _
; '', _  ; возможны два варианта либо @CRLF, либо ничего. По предпочтению.
'&(quot|#34);', _
'"', _
'&(amp|#38);', _
'&', _
'&(lt|#60);', _
'<', _
'&(gt|#62);', _
'>', _
'&(nbsp|#160);', _
' ', _
'&(iexcl|#161);', _
'chr(161)', _
'&(cent|#162);', _
'chr(162)', _
'&(pound|#163);', _
'chr(163)', _
'&(copy|#169);', _
'chr(169)', _
'&#(\d+);', _
'chr(\\1)', _
'([\r\n])[\s]+', _
@CRLF]


For $i = 1 to $search[0] Step 2
	$text = StringRegExpReplace($text,$search[$i],$search[$i+1])
Next


$file = FileOpen(@ScriptDir&'\Name.txt',2)
FileWrite($file, $text)
FileClose($file)
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,673
Репутация
2,486
Код:
#include <Array.au3>

#Region Entities Vars

Global $iEntity_quot = 34, $iEntity_amp = 38, $iEntity_apos = 39, $iEntity_lt = 60, $iEntity_gt = 62, $iEntity_nbsp = 160, $iEntity_iexcl = 161, $iEntity_cent = 162, $iEntity_pound = 163, $iEntity_curren = 164, $iEntity_yen = 165, $iEntity_brvbar = 166, $iEntity_sect = 167, $iEntity_uml = 168, $iEntity_copy = 169, $iEntity_ordf = 170, $iEntity_laquo = 171, $iEntity_not = 172, $iEntity_shy = 173, $iEntity_reg = 174, $iEntity_macr = 175, $iEntity_deg = 176, $iEntity_plusmn = 177, $iEntity_sup2 = 178, $iEntity_sup3 = 179, $iEntity_acute = 180, $iEntity_micro = 181, $iEntity_para = 182, $iEntity_middot = 183, $iEntity_cedil = 184, $iEntity_sup1 = 185, $iEntity_ordm = 186, $iEntity_raquo = 187, $iEntity_frac14 = 188, $iEntity_frac12 = 189, $iEntity_frac34 = 190, $iEntity_iquest = 191, $iEntity_Agrave = 192, $iEntity_Aacute = 193, $iEntity_Acirc = 194, $iEntity_Atilde = 195, $iEntity_Auml = 196, $iEntity_Aring = 197, $iEntity_AElig = 198, $iEntity_Ccedil = 199, $iEntity_Egrave = 200, $iEntity_Eacute = 201, $iEntity_Ecirc = 202, $iEntity_Euml = 203, $iEntity_Igrave = 204, $iEntity_Iacute = 205, $iEntity_Icirc = 206, $iEntity_Iuml = 207, $iEntity_ETH = 208, $iEntity_Ntilde = 209, $iEntity_Ograve = 210, $iEntity_Oacute = 211, $iEntity_Ocirc = 212, $iEntity_Otilde = 213, $iEntity_Ouml = 214, $iEntity_times = 215, $iEntity_Oslash = 216, $iEntity_Ugrave = 217, $iEntity_Uacute = 218, $iEntity_Ucirc = 219, $iEntity_Uuml = 220, $iEntity_Yacute = 221, $iEntity_THORN = 222, $iEntity_szlig = 223, $iEntity_agrave = 224, $iEntity_aacute = 225, $iEntity_acirc = 226, $iEntity_atilde = 227, $iEntity_auml = 228, $iEntity_aring = 229, $iEntity_aelig = 230, $iEntity_ccedil = 231, $iEntity_egrave = 232, $iEntity_eacute = 233, $iEntity_ecirc = 234, $iEntity_euml = 235, $iEntity_igrave = 236, $iEntity_iacute = 237, $iEntity_icirc = 238, $iEntity_iuml = 239, $iEntity_eth = 240, $iEntity_ntilde = 241, $iEntity_ograve = 242, $iEntity_oacute = 243, $iEntity_ocirc = 244, $iEntity_otilde = 245, $iEntity_ouml = 246, $iEntity_divide = 247, $iEntity_oslash = 248, $iEntity_ugrave = 249, $iEntity_uacute = 250, $iEntity_ucirc = 251, $iEntity_uuml = 252, $iEntity_yacute = 253, $iEntity_thorn = 254, $iEntity_yuml = 255, $iEntity_OElig = 338, $iEntity_oelig = 339, $iEntity_Scaron = 352, $iEntity_scaron = 353, $iEntity_Yuml = 376, $iEntity_fnof = 402, $iEntity_circ = 710, $iEntity_tilde = 732, $iEntity_Alpha = 913, $iEntity_Beta = 914, $iEntity_Gamma = 915, $iEntity_Delta = 916, $iEntity_Epsilon = 917, $iEntity_Zeta = 918, $iEntity_Eta = 919, $iEntity_Theta = 920, $iEntity_Iota = 921, $iEntity_Kappa = 922, $iEntity_Lambda = 923, $iEntity_Mu = 924, $iEntity_Nu = 925, $iEntity_Xi = 926, $iEntity_Omicron = 927, $iEntity_Pi = 928, $iEntity_Rho = 929, $iEntity_Sigma = 931, $iEntity_Tau = 932, $iEntity_Upsilon = 933, $iEntity_Phi = 934, $iEntity_Chi = 935, $iEntity_Psi = 936, $iEntity_Omega = 937, $iEntity_alpha = 945, $iEntity_beta = 946, $iEntity_gamma = 947, $iEntity_delta = 948, $iEntity_epsilon = 949, $iEntity_zeta = 950, $iEntity_eta = 951, $iEntity_theta = 952, $iEntity_iota = 953, $iEntity_kappa = 954, $iEntity_lambda = 955, $iEntity_mu = 956, $iEntity_nu = 957, $iEntity_xi = 958, $iEntity_omicron = 959, $iEntity_pi = 960, $iEntity_rho = 961, $iEntity_sigmaf = 962, $iEntity_sigma = 963, $iEntity_tau = 964, $iEntity_upsilon = 965, $iEntity_phi = 966, $iEntity_chi = 967, $iEntity_psi = 968, $iEntity_omega = 969, $iEntity_thetasym = 977, $iEntity_upsih = 978, $iEntity_piv = 982, $iEntity_ensp = 8194, $iEntity_emsp = 8195, $iEntity_thinsp = 8201, $iEntity_zwnj = 8204, $iEntity_zwj = 8205, $iEntity_lrm = 8206, $iEntity_rlm = 8207, $iEntity_ndash = 8211, $iEntity_mdash = 8212, $iEntity_lsquo = 8216, $iEntity_rsquo = 8217, $iEntity_sbquo = 8218, $iEntity_ldquo = 8220, $iEntity_rdquo = 8221, $iEntity_bdquo = 8222, $iEntity_dagger = 8224, $iEntity_Dagger = 8225, $iEntity_bull = 8226, $iEntity_hellip = 8230, $iEntity_permil = 8240, $iEntity_prime = 8242, $iEntity_Prime = 8243, $iEntity_lsaquo = 8249, $iEntity_rsaquo = 8250, $iEntity_oline = 8254, $iEntity_frasl = 8260

Global $iEntity_euro = 8364, $iEntity_image = 8465, $iEntity_weierp = 8472, $iEntity_real = 8476, $iEntity_trade = 8482, $iEntity_alefsym = 8501, $iEntity_larr = 8592, $iEntity_uarr = 8593, $iEntity_rarr = 8594, $iEntity_darr = 8595, $iEntity_harr = 8596, $iEntity_crarr = 8629, $iEntity_lArr = 8656, $iEntity_uArr = 8657, $iEntity_rArr = 8658, $iEntity_dArr = 8659, $iEntity_hArr = 8660, $iEntity_forall = 8704, $iEntity_part = 8706, $iEntity_exist = 8707, $iEntity_empty = 8709, $iEntity_nabla = 8711, $iEntity_isin = 8712, $iEntity_notin = 8713, $iEntity_ni = 8715, $iEntity_prod = 8719, $iEntity_sum = 8721, $iEntity_minus = 8722, $iEntity_lowast = 8727, $iEntity_radic = 8730, $iEntity_prop = 8733, $iEntity_infin = 8734, $iEntity_ang = 8736, $iEntity_and = 8743, $iEntity_or = 8744, $iEntity_cap = 8745, $iEntity_cup = 8746, $iEntity_int = 8747, $iEntity_there4 = 8756, $iEntity_sim = 8764, $iEntity_cong = 8773, $iEntity_asymp = 8776, $iEntity_ne = 8800, $iEntity_equiv = 8801, $iEntity_le = 8804, $iEntity_ge = 8805, $iEntity_sub = 8834, $iEntity_sup = 8835, $iEntity_nsub = 8836, $iEntity_sube = 8838, $iEntity_supe = 8839, $iEntity_oplus = 8853, $iEntity_otimes = 8855, $iEntity_perp = 8869, $iEntity_sdot = 8901, $iEntity_lceil = 8968, $iEntity_rceil = 8969, $iEntity_lfloor = 8970, $iEntity_rfloor = 8971, $iEntity_lang = 9001, $iEntity_rang = 9002, $iEntity_loz = 9674, $iEntity_spades = 9824, $iEntity_clubs = 9827, $iEntity_hearts = 9829, $iEntity_diams = 9830

Global $aEntity[65536]

$aEntity[$iEntity_quot] = "quot"
$aEntity[$iEntity_amp] = "amp"
$aEntity[$iEntity_apos] = "apos"
$aEntity[$iEntity_lt] = "lt"
$aEntity[$iEntity_gt] = "gt"
$aEntity[$iEntity_nbsp] = "nbsp"
$aEntity[$iEntity_iexcl] = "iexcl"
$aEntity[$iEntity_cent] = "cent"
$aEntity[$iEntity_pound] = "pound"
$aEntity[$iEntity_curren] = "curren"
$aEntity[$iEntity_yen] = "yen"
$aEntity[$iEntity_brvbar] = "brvbar"
$aEntity[$iEntity_sect] = "sect"
$aEntity[$iEntity_uml] = "uml"
$aEntity[$iEntity_copy] = "copy"
$aEntity[$iEntity_ordf] = "ordf"
$aEntity[$iEntity_laquo] = "laquo"
$aEntity[$iEntity_not] = "not"
$aEntity[$iEntity_shy] = "shy"
$aEntity[$iEntity_reg] = "reg"
$aEntity[$iEntity_macr] = "macr"
$aEntity[$iEntity_deg] = "deg"
$aEntity[$iEntity_plusmn] = "plusmn"
$aEntity[$iEntity_sup2] = "sup2"
$aEntity[$iEntity_sup3] = "sup3"
$aEntity[$iEntity_acute] = "acute"
$aEntity[$iEntity_micro] = "micro"
$aEntity[$iEntity_para] = "para"
$aEntity[$iEntity_middot] = "middot"
$aEntity[$iEntity_cedil] = "cedil"
$aEntity[$iEntity_sup1] = "sup1"
$aEntity[$iEntity_ordm] = "ordm"
$aEntity[$iEntity_raquo] = "raquo"
$aEntity[$iEntity_frac14] = "frac14"
$aEntity[$iEntity_frac12] = "frac12"
$aEntity[$iEntity_frac34] = "frac34"
$aEntity[$iEntity_iquest] = "iquest"
$aEntity[$iEntity_Agrave] = "Agrave"
$aEntity[$iEntity_Aacute] = "Aacute"
$aEntity[$iEntity_Acirc] = "Acirc"
$aEntity[$iEntity_Atilde] = "Atilde"
$aEntity[$iEntity_Auml] = "Auml"
$aEntity[$iEntity_Aring] = "Aring"
$aEntity[$iEntity_AElig] = "AElig"
$aEntity[$iEntity_Ccedil] = "Ccedil"
$aEntity[$iEntity_Egrave] = "Egrave"
$aEntity[$iEntity_Eacute] = "Eacute"
$aEntity[$iEntity_Ecirc] = "Ecirc"
$aEntity[$iEntity_Euml] = "Euml"
$aEntity[$iEntity_Igrave] = "Igrave"
$aEntity[$iEntity_Iacute] = "Iacute"
$aEntity[$iEntity_Icirc] = "Icirc"
$aEntity[$iEntity_Iuml] = "Iuml"
$aEntity[$iEntity_ETH] = "ETH"
$aEntity[$iEntity_Ntilde] = "Ntilde"
$aEntity[$iEntity_Ograve] = "Ograve"
$aEntity[$iEntity_Oacute] = "Oacute"
$aEntity[$iEntity_Ocirc] = "Ocirc"
$aEntity[$iEntity_Otilde] = "Otilde"
$aEntity[$iEntity_Ouml] = "Ouml"
$aEntity[$iEntity_times] = "times"
$aEntity[$iEntity_Oslash] = "Oslash"
$aEntity[$iEntity_Ugrave] = "Ugrave"
$aEntity[$iEntity_Uacute] = "Uacute"
$aEntity[$iEntity_Ucirc] = "Ucirc"
$aEntity[$iEntity_Uuml] = "Uuml"
$aEntity[$iEntity_Yacute] = "Yacute"
$aEntity[$iEntity_THORN] = "THORN"
$aEntity[$iEntity_szlig] = "szlig"
$aEntity[$iEntity_agrave] = "agrave"
$aEntity[$iEntity_aacute] = "aacute"
$aEntity[$iEntity_acirc] = "acirc"
$aEntity[$iEntity_atilde] = "atilde"
$aEntity[$iEntity_auml] = "auml"
$aEntity[$iEntity_aring] = "aring"
$aEntity[$iEntity_aelig] = "aelig"
$aEntity[$iEntity_ccedil] = "ccedil"
$aEntity[$iEntity_egrave] = "egrave"
$aEntity[$iEntity_eacute] = "eacute"
$aEntity[$iEntity_ecirc] = "ecirc"
$aEntity[$iEntity_euml] = "euml"
$aEntity[$iEntity_igrave] = "igrave"
$aEntity[$iEntity_iacute] = "iacute"
$aEntity[$iEntity_icirc] = "icirc"
$aEntity[$iEntity_iuml] = "iuml"
$aEntity[$iEntity_eth] = "eth"
$aEntity[$iEntity_ntilde] = "ntilde"
$aEntity[$iEntity_ograve] = "ograve"
$aEntity[$iEntity_oacute] = "oacute"
$aEntity[$iEntity_ocirc] = "ocirc"
$aEntity[$iEntity_otilde] = "otilde"
$aEntity[$iEntity_ouml] = "ouml"
$aEntity[$iEntity_divide] = "divide"
$aEntity[$iEntity_oslash] = "oslash"
$aEntity[$iEntity_ugrave] = "ugrave"
$aEntity[$iEntity_uacute] = "uacute"
$aEntity[$iEntity_ucirc] = "ucirc"
$aEntity[$iEntity_uuml] = "uuml"
$aEntity[$iEntity_yacute] = "yacute"
$aEntity[$iEntity_thorn] = "thorn"
$aEntity[$iEntity_yuml] = "yuml"
$aEntity[$iEntity_OElig] = "OElig"
$aEntity[$iEntity_oelig] = "oelig"
$aEntity[$iEntity_Scaron] = "Scaron"
$aEntity[$iEntity_scaron] = "scaron"
$aEntity[$iEntity_Yuml] = "Yuml"
$aEntity[$iEntity_fnof] = "fnof"
$aEntity[$iEntity_circ] = "circ"
$aEntity[$iEntity_tilde] = "tilde"
$aEntity[$iEntity_Alpha] = "Alpha"
$aEntity[$iEntity_Beta] = "Beta"
$aEntity[$iEntity_Gamma] = "Gamma"
$aEntity[$iEntity_Delta] = "Delta"
$aEntity[$iEntity_Epsilon] = "Epsilon"
$aEntity[$iEntity_Zeta] = "Zeta"
$aEntity[$iEntity_Eta] = "Eta"
$aEntity[$iEntity_Theta] = "Theta"
$aEntity[$iEntity_Iota] = "Iota"
$aEntity[$iEntity_Kappa] = "Kappa"
$aEntity[$iEntity_Lambda] = "Lambda"
$aEntity[$iEntity_Mu] = "Mu"
$aEntity[$iEntity_Nu] = "Nu"
$aEntity[$iEntity_Xi] = "Xi"
$aEntity[$iEntity_Omicron] = "Omicron"
$aEntity[$iEntity_Pi] = "Pi"
$aEntity[$iEntity_Rho] = "Rho"
$aEntity[$iEntity_Sigma] = "Sigma"
$aEntity[$iEntity_Tau] = "Tau"
$aEntity[$iEntity_Upsilon] = "Upsilon"
$aEntity[$iEntity_Phi] = "Phi"
$aEntity[$iEntity_Chi] = "Chi"
$aEntity[$iEntity_Psi] = "Psi"
$aEntity[$iEntity_Omega] = "Omega"
$aEntity[$iEntity_alpha] = "alpha"
$aEntity[$iEntity_beta] = "beta"
$aEntity[$iEntity_gamma] = "gamma"
$aEntity[$iEntity_delta] = "delta"
$aEntity[$iEntity_epsilon] = "epsilon"
$aEntity[$iEntity_zeta] = "zeta"
$aEntity[$iEntity_eta] = "eta"
$aEntity[$iEntity_theta] = "theta"
$aEntity[$iEntity_iota] = "iota"
$aEntity[$iEntity_kappa] = "kappa"
$aEntity[$iEntity_lambda] = "lambda"
$aEntity[$iEntity_mu] = "mu"
$aEntity[$iEntity_nu] = "nu"
$aEntity[$iEntity_xi] = "xi"
$aEntity[$iEntity_omicron] = "omicron"
$aEntity[$iEntity_pi] = "pi"
$aEntity[$iEntity_rho] = "rho"
$aEntity[$iEntity_sigmaf] = "sigmaf"
$aEntity[$iEntity_sigma] = "sigma"
$aEntity[$iEntity_tau] = "tau"
$aEntity[$iEntity_upsilon] = "upsilon"
$aEntity[$iEntity_phi] = "phi"
$aEntity[$iEntity_chi] = "chi"
$aEntity[$iEntity_psi] = "psi"
$aEntity[$iEntity_omega] = "omega"
$aEntity[$iEntity_thetasym] = "thetasym"
$aEntity[$iEntity_upsih] = "upsih"
$aEntity[$iEntity_piv] = "piv"
$aEntity[$iEntity_ensp] = "ensp"
$aEntity[$iEntity_emsp] = "emsp"
$aEntity[$iEntity_thinsp] = "thinsp"
$aEntity[$iEntity_zwnj] = "zwnj"
$aEntity[$iEntity_zwj] = "zwj"
$aEntity[$iEntity_lrm] = "lrm"
$aEntity[$iEntity_rlm] = "rlm"
$aEntity[$iEntity_ndash] = "ndash"
$aEntity[$iEntity_mdash] = "mdash"
$aEntity[$iEntity_lsquo] = "lsquo"
$aEntity[$iEntity_rsquo] = "rsquo"
$aEntity[$iEntity_sbquo] = "sbquo"
$aEntity[$iEntity_ldquo] = "ldquo"
$aEntity[$iEntity_rdquo] = "rdquo"
$aEntity[$iEntity_bdquo] = "bdquo"
$aEntity[$iEntity_dagger] = "dagger"
$aEntity[$iEntity_Dagger] = "Dagger"
$aEntity[$iEntity_bull] = "bull"
$aEntity[$iEntity_hellip] = "hellip"
$aEntity[$iEntity_permil] = "permil"
$aEntity[$iEntity_prime] = "prime"
$aEntity[$iEntity_Prime] = "Prime"
$aEntity[$iEntity_lsaquo] = "lsaquo"
$aEntity[$iEntity_rsaquo] = "rsaquo"
$aEntity[$iEntity_oline] = "oline"
$aEntity[$iEntity_frasl] = "frasl"
$aEntity[$iEntity_euro] = "euro"
$aEntity[$iEntity_image] = "image"
$aEntity[$iEntity_weierp] = "weierp"
$aEntity[$iEntity_real] = "real"
$aEntity[$iEntity_trade] = "trade"
$aEntity[$iEntity_alefsym] = "alefsym"
$aEntity[$iEntity_larr] = "larr"
$aEntity[$iEntity_uarr] = "uarr"
$aEntity[$iEntity_rarr] = "rarr"
$aEntity[$iEntity_darr] = "darr"
$aEntity[$iEntity_harr] = "harr"
$aEntity[$iEntity_crarr] = "crarr"
$aEntity[$iEntity_lArr] = "lArr"
$aEntity[$iEntity_uArr] = "uArr"
$aEntity[$iEntity_rArr] = "rArr"
$aEntity[$iEntity_dArr] = "dArr"
$aEntity[$iEntity_hArr] = "hArr"
$aEntity[$iEntity_forall] = "forall"
$aEntity[$iEntity_part] = "part"
$aEntity[$iEntity_exist] = "exist"
$aEntity[$iEntity_empty] = "empty"
$aEntity[$iEntity_nabla] = "nabla"
$aEntity[$iEntity_isin] = "isin"
$aEntity[$iEntity_notin] = "notin"
$aEntity[$iEntity_ni] = "ni"
$aEntity[$iEntity_prod] = "prod"
$aEntity[$iEntity_sum] = "sum"
$aEntity[$iEntity_minus] = "minus"
$aEntity[$iEntity_lowast] = "lowast"
$aEntity[$iEntity_radic] = "radic"
$aEntity[$iEntity_prop] = "prop"
$aEntity[$iEntity_infin] = "infin"
$aEntity[$iEntity_ang] = "ang"
$aEntity[$iEntity_and] = "and"
$aEntity[$iEntity_or] = "or"
$aEntity[$iEntity_cap] = "cap"
$aEntity[$iEntity_cup] = "cup"
$aEntity[$iEntity_int] = "int"
$aEntity[$iEntity_there4] = "there4"
$aEntity[$iEntity_sim] = "sim"
$aEntity[$iEntity_cong] = "cong"
$aEntity[$iEntity_asymp] = "asymp"
$aEntity[$iEntity_ne] = "ne"
$aEntity[$iEntity_equiv] = "equiv"
$aEntity[$iEntity_le] = "le"
$aEntity[$iEntity_ge] = "ge"
$aEntity[$iEntity_sub] = "sub"
$aEntity[$iEntity_sup] = "sup"
$aEntity[$iEntity_nsub] = "nsub"
$aEntity[$iEntity_sube] = "sube"
$aEntity[$iEntity_supe] = "supe"
$aEntity[$iEntity_oplus] = "oplus"
$aEntity[$iEntity_otimes] = "otimes"
$aEntity[$iEntity_perp] = "perp"
$aEntity[$iEntity_sdot] = "sdot"
$aEntity[$iEntity_lceil] = "lceil"
$aEntity[$iEntity_rceil] = "rceil"
$aEntity[$iEntity_lfloor] = "lfloor"
$aEntity[$iEntity_rfloor] = "rfloor"
$aEntity[$iEntity_lang] = "lang"
$aEntity[$iEntity_rang] = "rang"
$aEntity[$iEntity_loz] = "loz"
$aEntity[$iEntity_spades] = "spades"
$aEntity[$iEntity_clubs] = "clubs"
$aEntity[$iEntity_hearts] = "hearts"
$aEntity[$iEntity_diams] = "diams"

#EndRegion Entities Vars

$sEncoded_Str = _HTMLEncode('AutoIt ®')
$sDecoded_Str = _HTMLDecode($sEncoded_Str)

MsgBox(64, '_HTMLEncode', $sEncoded_Str)
MsgBox(64, '_HTMLDecode', $sDecoded_Str)


;===============================================================================
;
; 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($aEntity, $X3[$i], 0, 0, 1)))
	Next
	$Decoded = $Str
	Return $Decoded
EndFunc   ;==>_HTMLDecode
 

Garrett

Модератор
Локальный модератор
Сообщения
3,999
Репутация
967
CreatoR
А в чём разница :scratch:
Код:
MsgBox(64, 'Title', _HTMLDecode('AutoIt ®'))
MsgBox(64, 'Title', 'AutoIt ®')
 

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,673
Репутация
2,486
Вот тут есть немного другая реализация по теме, правда не кодирует цифровые символы.
Позже выложу модификацию этой UDF.
 
Автор
inververs

inververs

AutoIT Гуру
Сообщения
2,135
Репутация
465
Спасибо всем за решения. Выручаете очередной раз :beer:
 
Верх