Convertir des entités HTML
Variable à déclarer
variable entities {
"à" "à" "à" "à" "á" "á" "â" "â"
"ã" "ã" "ä" "ä" "å" "å" "æ" "æ"
"ç" "ç" "è" "è" "é" "é" "ê" "ê"
"ë" "ë" "ì" "ì" "í" "í" "î" "î"
"ï" "ï" "ð" "ð" "ñ" "ñ" "ò" "ò"
"ó" "ó" "ô" "ô" "õ" "õ" "ö" "ö"
"÷" "÷" "ø" "ø" "ù" "ù" "ú" "ú"
"û" "û" "ü" "ü" "ý" "ý" "þ" "þ"
"ÿ" "ÿ" """ "\"" "&" "&" "€" "€"
"œ" "œ" "Ÿ" "Ÿ" " " " " "¡" "¡"
"¢" "¢" "£" "£" "¤" "¤" "¥" "¥"
"¦" "¦" "&brkbar;" "¦" "§" "§" "¨" "¨"
"¨" "¨" "©" "©" "ª" "ª" "«" "«"
"¬" "¬" "­" "-" "®" "®" "¯" "¯"
"&hibar;" "¯" "°" "°" "±" "±" "²" "²"
"³" "³" "´" "´" "µ" "µ" "¶" "¶"
"·" "·" "¸" "¸" "¹" "¹" "º" "º"
"»" "»" "¼" "¼" "½" "½" "¾" "¾"
"¿" "¿" "À" "À" "Á" "Á" "Â" "Â"
"Ã" "Ã" "Ä" "Ä" "Å" "Å" "Æ" "Æ"
"Ç" "Ç" "È" "È" "É" "É" "Ê" "Ê"
"Ë" "Ë" "Ì" "Ì" "Í" "Í" "Î" "Î"
"Ï" "Ï" "Ð" "Ð" "Đ" "Ð" "Ñ" "Ñ"
"Ò" "Ò" "Ó" "Ó" "Ô" "Ô" "Õ" "Õ"
"Ö" "Ö" "×" "×" "Ø" "Ø" "Ù" "Ù"
"Ú" "Ú" "Û" "Û" "Ü" "Ü" "Ý" "Ý"
"Þ" "Þ" "ß" "ß" "\r" "\n" "\t" ""
"'" "\'" "'" "\'" "'" "\'" "\" "\\"
""" "\"" "&" "&" "[" "\[" "/" "/"
"<" "<" ">" ">" "]" "\]" "/" "/"
"(" "\(" ")" "\)" "£" "£" "!" "!"
"¨" "¨" "©" "©" "«" "«" "­" ""
"®" "®" "´" "´" "·" "·" "¹" "¹"
"»" "»" "¼" "¼" "½" "½" "¾" "¾"
"À" "À" "Á" "Á" "Â" "Â" "Ã" "Ã"
"Ä" "Ä" "Å" "Å" "Æ" "Æ" "Ç" "Ç"
"È" "È" "É" "É" "Ê" "Ê" "Ë" "Ë"
"Ì" "Ì" "Í" "Í" "Î" "Î" "Ï" "Ï"
"Ð" "Ð" "Ñ" "Ñ" "Ò" "Ò" "Ó" "Ó"
"Ô" "Ô" "Õ" "Õ" "Ö" "Ö" "×" "×"
"Ø" "Ø" "Ù" "Ù" "Ú" "Ú" "Û" "Û"
"Ü" "Ü" "Ý" "Ý" "Þ" "Þ" "ß" "ß"
"à" "à" "á" "á" "â" "â" "ã" "ã"
"ä" "ä" "å" "å" "æ" "æ" "ç" "ç"
"è" "è" "é" "é" "ê" "ê" "ë" "ë"
"ì" "ì" "í" "í" "î" "î" "ï" "ï"
"ð" "ð" "ñ" "ñ" "ò" "ò" "ó" "ó"
"ô" "ô" "õ" "õ" "ö" "ö" "÷" "÷"
"ø" "ø" "ù" "ù" "ú" "ú" "û" "û"
"ü" "ü" "ý" "ý" "þ" "þ"
}
Procédure
proc html_entities_decode {data} {
variable entities
return [::tcl::string::map $entities $data]
}
proc html_entities_encode {data} {
variable entities
return [::tcl::string::map [lreverse $entities] $data]
}
La procédure suivante convertira automatiquement toutes les entités html décimales ou hexadécimales ( formats ?? ou ??; ).
proc html_hexdec_decode {data} {
regsub -all {([[:digit:]]{1,5});} $data {[format %c [string trimleft "\1" "0"]]} data
regsub -all {([[:xdigit:]]{1,4});} $data {[format %c [scan "\1" %x]]} data
return [subst $data]
}