UNPKG

phpjs

Version:

php.js offers community built php functions in javascript

44 lines (39 loc) 1.41 kB
function html_entity_decode(string, quote_style) { // discuss at: http://phpjs.org/functions/html_entity_decode/ // original by: john (http://www.jd-tech.net) // input by: ger // input by: Ratheous // input by: Nick Kolosov (http://sammy.ru) // improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // improved by: marc andreu // revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // bugfixed by: Onno Marsman // bugfixed by: Brett Zamir (http://brett-zamir.me) // bugfixed by: Fox // depends on: get_html_translation_table // example 1: html_entity_decode('Kevin & van Zonneveld'); // returns 1: 'Kevin & van Zonneveld' // example 2: html_entity_decode('<'); // returns 2: '<' var hash_map = {}, symbol = '', tmp_str = '', entity = ''; tmp_str = string.toString(); if (false === (hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style))) { return false; } // fix & problem // http://phpjs.org/functions/get_html_translation_table:416#comment_97660 delete(hash_map['&']); hash_map['&'] = '&'; for (symbol in hash_map) { entity = hash_map[symbol]; tmp_str = tmp_str.split(entity) .join(symbol); } tmp_str = tmp_str.split(''') .join("'"); return tmp_str; }