Shoutbox

[Question] How to decode HTML codes? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Question] How to decode HTML codes? (/showthread.php?tid=70572)

[Question] How to decode HTML codes? by tryxter on 01-11-2007 at 01:36 PM

Any idea on how to decode this kind of html codes?
I've already tried decodeURI() and it doesn't work (at least as expected).

ÁFRICA

I hope the solution doesn't pass by creating a switch for every encoded word... :-#


RE: [Question] How to decode HTML codes? by Silentdragon on 01-11-2007 at 06:03 PM

decodeURI()
decodeURIComponent()

I tried with both of those and it gave me the letter Á which is what it is.

I even tried unescape() which works fine too.

So not sure what to say, unless maybe you can further explain the how it doesn't work as expected.


RE: [Question] How to decode HTML codes? by tryxter on 01-11-2007 at 06:26 PM

Can you explain how you did it? I've tried, but somehow it didn't decoded successfully...

I've tried decodeURI("Á"); and it returns the same thing (Á).
I guess I'm doing something wrong... :\

Thanks


RE: [Question] How to decode HTML codes? by tryxter on 01-12-2007 at 07:43 PM

Can anyone answer the question, please?

Thanks


RE: [Question] How to decode HTML codes? by albert on 01-12-2007 at 07:47 PM

Á is a simple code to replace a letter
to "decode" you can simple check the codes significations here :

http://www.ascii.cl/htmlcodes.htm


RE: [Question] How to decode HTML codes? by tryxter on 01-12-2007 at 07:52 PM

That was only an example... There are many more characters too translate.


RE: [Question] How to decode HTML codes? by Mnjul on 01-12-2007 at 08:18 PM

If you are able to extract the number (193 in your example) from the string, then you can call the fromCharCode method of String

Example:

code:
var s="193";
var c=parseInt(s);
var s2=String.fromCharCode(c);
Debug.Trace(s2);


RE: [Question] How to decode HTML codes? by tryxter on 01-13-2007 at 12:38 AM

I guess that's a better solution.
Anyway, if someone finds out how to work with decodeURI(), can be the best solution.

Thanks again


RE: [Question] How to decode HTML codes? by Eljay on 01-13-2007 at 10:42 AM

Just made a little function for removing html codes in this format (i would add support for all the & style codes but theres too many of the darned things :P)

function: (one line, ok kinda long line but still one line!)

code:
function htmldecode(encodedString){ return encodedString.replace(/&#([0-9]+);/g, function(a,b){ return String.fromCharCode( b); } ); }

example:
code:
htmldecode("Hello World"); //returns "Hello World"