And yes there is a more elegant way to do this. But I thought it might be useful for to give an idea to people who are looking out for this.
function decodeHTML(str) {
/*
* @Param : str - your native html string to be decoded *
* @Return : str - decoded html *
* @Created : 19th Jan 2011 *
*/
str=str.replace(/–/gi, "–");
str=str.replace(/—/gi, "—");
str=str.replace(/¡/gi, "¡");
str=str.replace(/¿/gi, "¿");
str=str.replace(/"/gi, "\"");
str=str.replace(/“/gi, "“");
str=str.replace(/”/gi, "”");
str=str.replace(/‘/gi, "‘");
str=str.replace(/’/gi, "’");
str=str.replace(/«/gi, "«");
str=str.replace(/»/gi, "»");
str=str.replace(/&/gi, "&");
str=str.replace(/¢/gi, "¢");
str=str.replace(/©/gi, "©");
str=str.replace(/÷/gi, "÷");
str=str.replace(/>/gi, ">");
str=str.replace(/</gi, "<");
str=str.replace(/µ/gi, "µ");
str=str.replace(/·/gi, "·");
str=str.replace(/¶/gi, "¶");
str=str.replace(/±/gi, "±");
str=str.replace(/€/gi, "€");
str=str.replace(/£/gi, "£");
str=str.replace(/®/gi, "®");
str=str.replace(/§/gi, "§");
str=str.replace(/™/gi, "™");
str=str.replace(/¥/gi, "¥");
str=str.replace(/á/gi, "á");
str=str.replace(/Á/gi, "Á");
str=str.replace(/à/gi, "à");
str=str.replace(/À/gi, "À");
str=str.replace(/â/gi, "â");
str=str.replace(/Â/gi, "Â");
str=str.replace(/å/gi, "å");
str=str.replace(/Å/gi, "Å");
str=str.replace(/ã/gi, "ã");
str=str.replace(/Ã/gi, "Ã");
str=str.replace(/ä/gi, "ä");
str=str.replace(/Ä/gi, "Ä");
str=str.replace(/æ/gi, "æ");
str=str.replace(/Æ/gi, "Æ");
str=str.replace(/ç/gi, "ç");
str=str.replace(/Ç/gi, "Ç");
str=str.replace(/é/gi, "é");
str=str.replace(/É/gi, "É");
str=str.replace(/è/gi, "è");
str=str.replace(/È/gi, "È");
str=str.replace(/ê/gi, "ê");
str=str.replace(/Ê/gi, "Ê");
str=str.replace(/ë/gi, "ë");
str=str.replace(/Ë/gi, "Ë");
str=str.replace(/í/gi, "í");
str=str.replace(/Í/gi, "Í");
str=str.replace(/ì/gi, "ì");
str=str.replace(/Ì/gi, "Ì");
str=str.replace(/î/gi, "î");
str=str.replace(/Î/gi, "Î");
str=str.replace(/ï/gi, "ï");
str=str.replace(/Ï/gi, "Ï");
str=str.replace(/ñ/gi, "ñ");
str=str.replace(/Ñ/gi, "Ñ");
str=str.replace(/ó/gi, "ó");
str=str.replace(/Ó/gi, "Ó");
str=str.replace(/ò/gi, "ò");
str=str.replace(/Ò/gi, "Ò");
str=str.replace(/ô/gi, "ô");
str=str.replace(/Ô/gi, "Ô");
str=str.replace(/ø/gi, "ø");
str=str.replace(/Ø/gi, "Ø");
str=str.replace(/õ/gi, "õ");
str=str.replace(/Õ/gi, "Õ");
str=str.replace(/ö/gi, "ö");
str=str.replace(/Ö/gi, "Ö");
str=str.replace(/ß/gi, "ß");
str=str.replace(/ú/gi, "ú");
str=str.replace(/Ú/gi, "Ú");
str=str.replace(/ù/gi, "ù");
str=str.replace(/Ù/gi, "Ù");
str=str.replace(/û/gi, "û");
str=str.replace(/Û/gi, "Û");
str=str.replace(/ü/gi, "ü");
str=str.replace(/Ü/gi, "Ü");
str=str.replace(/ÿ/gi, "ÿ");
return str;
}
Hope this helps :)
@URLEncode
ReplyDeleteThanks :)
ReplyDeleteBut that does not work with client side javascript :)