Reputation: 5199
I am looking for a prototype.js or other js function to decode html encoded entities. I am using 1.6.1 of Prototype.js and unescapeHTML does not work on French encoded characters. I believe from what I read, that is only works on a few select entities.
Can someone point me in the right direction on how I would do something like this with javascript? I would normally be able to use the .text() with jQuery, but right now the main library used is Prototype.
Thanks.
Upvotes: 0
Views: 870
Reputation: 76208
How about this:
function decode(str) {
var div = document.createElement('div');
div.innerHTML = str;
return div.innerHTML;
}
Doesn't return &
properly but works fine for french ones. Updated fiddle:http://jsfiddle.net/mrchief/MRqnQ/3/
Upvotes: 3
Reputation: 7315
Try using that :
http://phpjs.org/functions/htmlentities:425
Upvotes: 0
Reputation: 1064
The built-in decodeURI
function may be what you're looking for. It ignores "special" characters, but will turn an arbitrary URI-encoded string into what it represents.
Example:
encodeURI("Déjà vu") = "D%C3%A9j%C3%A0%20vu"
decodeURI("D%C3%A9j%C3%A0%20vu") = "Déjà vu"
An alternative may be to use a regular expression.
Upvotes: 0