Shoutbox

HTML entities(?) - 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: HTML entities(?) (/showthread.php?tid=69110)

HTML entities(?) by pollolibredegrasa on 12-03-2006 at 04:45 PM

OK, so I have written a small script that gets a slogan from http://www.sloganizer.net using whatever input the user wants.

However, if the user enters certain characters, it will return the special code for them in the string.

For example, If the user enters a ", it shows in the debugger as: \"

Is there any way to convert these back to their corresponding characters? I assume there probably is using regular expression, but I just can't get my head around them, so any help would be appreciated.


RE: HTML entities(?) by mickael9 on 12-03-2006 at 06:18 PM

code:
var htmlentities = {
    '"'   : '"',
    ' '   : ' ',
    '''   : '\'',
    '&'    : '&',
    '\\\''     : '\''
}
String.prototype.htmldecode = function()
{
    var sRet = this;
   
    for (var sKey in htmlentities)
    {
        sRet = sRet.replace(new RegExp(sKey, 'g'), htmlentities[sKey]);
    }
   
    return sRet;
}

var decodedText = myText.htmldecode();

RE: HTML entities(?) by pollolibredegrasa on 12-04-2006 at 05:57 PM

Thanks, it sort of works, but it still leaves a \ before the character. Is there a way to remove that too?


RE: HTML entities(?) by mickael9 on 12-04-2006 at 07:18 PM

Edited ...


RE: RE: HTML entities(?) by CookieRevised on 12-05-2006 at 12:18 AM

quote:
Originally posted by mickael9
code:
var htmlentities = {
    '"'   : '"',
    ' '   : ' ',
    '''   : '\'',
    '&'    : '&',
    '\\\''     : '\''
}

multiply that list be several thousand possible entities and you have your complete script.

Otherwise such a function will always leave some entities behind.

Just to say that making something like this requires a extremely huge list...
With the result that your for...loop and the use of an object creator for each element is going to slow down your script a hell of a lot.

For situations like this, I suggest you actually dish regular expressions and make your own string manipulation routines.

Or better yet, use existing ActiveX objects which might do this job for you (I'm thinking about the XML object and that stuff)
RE: RE: RE: HTML entities(?) by pollolibredegrasa on 12-06-2006 at 03:08 PM

quote:
Originally posted by CookieRevised
Or better yet, use existing ActiveX objects which might do this job for you (I'm thinking about the XML object and that stuff)

Thanks Cookie, I had a look at the XML object and got it to partially work. Some things don't get replaced however, such as £ for £. Is there a reason for this (like, these are not supported by XML or something?)
RE: HTML entities(?) by CookieRevised on 12-07-2006 at 12:38 AM

I can't think of any reason other than that specific activex not supporting HTML 3.2 tags (which is already pretty old by now, so... eeek)...

Or XHTML doesn't support that specific entity (which again seems very strange though)?

the pound entitiy is part of the ISO Latin/1 8859-1 list, so it should be supported :/

sorry. :(