note 75545 deleted from function.html-entity-decode by nlopess

From: Date: Tue, 19 Jun 2007 12:27:02 +0000
Subject: note 75545 deleted from function.html-entity-decode by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-127770@lists.php.net to get a copy of this message
Note Submitter: motin at demomusic dot nu ---- In case you develop php-generated XML in an AJAX application or the less recommendde but easier php-generated-output-used-to-update-innerHTML-of-div type of Javascript functionality, you probably want to use htmlentities() on the generated output. To be able to extract information from the generated information afterwards, you might need html_entity_decode() in Javascript: function html_entity_decode(str) { var ent = new Object() ent['apos'] = 39 // from XML, not present in HTML4 ent['quot'] = 34 ent['amp'] = 38 ent['lt'] = 60 // Insert full list from http://www.thescripts.com/forum/thread642230.html here (this note was deemed to large to post this function with the whole list) ent['spades'] = 9824 ent['clubs'] = 9827 ent['hearts'] = 9829 ent['diams'] = 9830 var xml = str; for (var i in ent) xml = xml.replace(new RegExp('&'+i+';','g'), //'gi' instead of 'g' for case-insensitivity String.fromCharCode(ent[i])); xml = xml.replace(/(&)(#)(\d{1,})(;)/g, function (tot,amp,cr,cp,sem) { return String.fromCharCode(cp) } ) return xml; } Originally from here: http://www.thescripts.com/forum/thread642230.html Thanks Bart! All I did was to wrap it up in a function and turned of case-insensitivity (since it made no distinction between Ouml and ouml with it on...)

« previous php.notes (#127770) next »