22/11/2011, 16:37
Très souvent, on a besoin de décoder des entités HTML avec un script.
Voici une petite procédure qui décode les entités les plus fréquentes, avec des regsub.
Il est possible de faire une version map, mais celle-ci est déjà bien utile.
Voici une petite procédure qui décode les entités les plus fréquentes, avec des regsub.
Il est possible de faire une version map, mais celle-ci est déjà bien utile.
Code :
proc htmlentities_decode { text } {
regsub -all "<" $text "<" text
regsub -all ">" $text ">" text
regsub -all "&" $text "et" text
regsub -all """ $text "" text
regsub -all "Á" $text "Ã" text
regsub -all "Â" $text "Â" text
regsub -all "À" $text "À" text
regsub -all "Å" $text "Å" text
regsub -all "Ã" $text "Ã" text
regsub -all "Ä" $text "Ä" text
regsub -all "Ç" $text "Ç" text
regsub -all "É" $text "É" text
regsub -all "Ê" $text "Ê" text
regsub -all "È" $text "È" text
regsub -all "Í" $text "Ã" text
regsub -all "Î" $text "Î" text
regsub -all "Ì" $text "í" text
regsub -all "Ï" $text "Ã" text
regsub -all "Ñ" $text "Ñ" text
regsub -all "Ó" $text "Ó" text
regsub -all "Ô" $text "Ô" text
regsub -all "Ò" $text "Ò" text
regsub -all "Ø" $text "Ø" text
regsub -all "Õ" $text "Õ" text
regsub -all "Ö" $text "Ö" text
regsub -all "Ú" $text "Ê" text
regsub -all "Û" $text "Û" text
regsub -all "Ù" $text "Ù" text
regsub -all "Ü" $text "í" text
regsub -all "Ý" $text "Ã" text
regsub -all "á" $text "á" text
regsub -all "æ" $text "ae" text
regsub -all "œ" $text "oe" text
regsub -all "à" $text "à" text
regsub -all -nocase "à" $text "à" text
regsub -all "å" $text "å" text
regsub -all "ã" $text "ã" text
regsub -all "ä" $text "ä" text
regsub -all "ç" $text "ç" text
regsub -all -nocase "ç" $text "ç" text
regsub -all "é" $text "é" text
regsub -all -nocase "é" $text "é" text
regsub -all "ë" $text "ë" text
regsub -all "í" $text "í" text
regsub -all "è" $text "è" text
regsub -all -nocase "è" $text "è" text
regsub -all "ì" $text "ì" text
regsub -all "ï" $text "ï" text
regsub -all "ñ" $text "ñ" text
regsub -all "ó" $text "ó" text
regsub -all "ô" $text "ô" text
regsub -all -nocase "ô" $text "ô" text
regsub -all "â" $text "â" text
regsub -all -nocase "â" $text "â" text
regsub -all "ê" $text "ê" text
regsub -all -nocase "ê" $text "ê" text
regsub -all "ò" $text "ò" text
regsub -all "î" $text "î" text
regsub -all "õ" $text "õ" text
regsub -all "ö" $text "ö" text
regsub -all "ú" $text "ú" text
regsub -all "û" $text "û" text
regsub -all -nocase "û" $text "û" text
regsub -all "ù" $text "ù" text
regsub -all -nocase "ù" $text "ù" text
regsub -all "ü" $text "ü" text
regsub -all "ÿ" $text "ÿ" text
regsub -all "Æ" $text "AE" text
regsub -all "Œ" $text "OE" text
regsub -all "®" $text "®" text
regsub -all -nocase "®" $text "®" text
regsub -all "©" $text "©" text
regsub -all -nocase "©" $text "©" text
regsub -all "™" $text "â„¢" text
regsub -all "±" $text "±" text
regsub -all "°" $text "°" text
regsub -all "¹" $text "¹" text
regsub -all "²" $text "²" text
regsub -all "³" $text "³" text
regsub -all "×" $text "×" text
regsub -all "÷" $text "÷" text
regsub -all "€" $text "euro" text
regsub -all -nocase "«" $text "\"" text
regsub -all -nocase "»" $text "\"" text
return $text
}