Convert HTML Character Entities back to regular text using javascript -
the questions says :)
eg. have >
, need >
using javascript
update: seems jquery easy way out. but, nice have lightweight solution. more function capable itself.
you this:
string.prototype.decodehtml = function() { var map = {"gt":">" /* , … */}; return this.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, function($0, $1) { if ($1[0] === "#") { return string.fromcharcode($1[1].tolowercase() === "x" ? parseint($1.substr(2), 16) : parseint($1.substr(1), 10)); } else { return map.hasownproperty($1) ? map[$1] : $0; } }); };
Comments
Post a Comment