note 75545 added to function.html-entity-decode
| From: | motin at demomusic dot nu | Date: | Tue, 05 Jun 2007 00:03:41 +0000 |
| Subject: | note 75545 added to function.html-entity-decode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127203@lists.php.net to get a copy of this message | ||
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...)
----
Server IP: 129.16.214.50
Probable Submitter: 84.217.2.120
----
Manual Page -- http://www.php.net/manual/en/function.html-entity-decode.php
Edit -- https://master.php.net/note/edit/75545
Del: integrated -- https://master.php.net/note/delete/75545/integrated
Del: useless -- https://master.php.net/note/delete/75545/useless
Del: bad code -- https://master.php.net/note/delete/75545/bad+code
Del: spam -- https://master.php.net/note/delete/75545/spam
Del: non-english -- https://master.php.net/note/delete/75545/non-english
Del: in docs -- https://master.php.net/note/delete/75545/in+docs
Del: other reasons-- https://master.php.net/note/delete/75545
Reject -- https://master.php.net/note/reject/75545
Search -- https://master.php.net/manage/user-notes.php