Javascript String unhtmlspecialchars()
/**//from www . j a v a 2 s . c o m @Name: String.prototype.unhtmlspecialchars @Author: Paul Visco @Version: 1.0 12/14/12 @Description: Escapes same chars as PHP htmlspecialchars @Return: Boolean Returns true if the string is empty, false otherwise @Example: var str = '<p>hello</p>'; var newString = str.unhtmlspecialchars(); //newString = '<p>hello</p>' */ String.prototype.unhtmlspecialchars = function(){ var s = this.replace(/&/g, '&'); s = s.replace(/'/g, "'"); s = s.replace(/"/g, '"'); s = s.replace(/</g, '<'); s = s.replace(/>/g, '>'); return s; };