2 * More info at: http://phpjs.org
4 * This is version: 3.25
5 * php.js is copyright 2011 Kevin van Zonneveld.
7 * Portions copyright Brett Zamir (http://brett-zamir.me), Kevin van Zonneveld
8 * (http://kevin.vanzonneveld.net), Onno Marsman, Theriault, Michael White
9 * (http://getsprink.com), Waldo Malqui Silva, Paulo Freitas, Jonas Raoni
10 * Soares Silva (http://www.jsfromhell.com), Jack, Philip Peterson, Legaev
11 * Andrey, Ates Goral (http://magnetiq.com), Ratheous, Alex, Rafa? Kukawski
12 * (http://blog.kukawski.pl), Martijn Wieringa, lmeyrick
13 * (https://sourceforge.net/projects/bcmath-js/), Nate, Enrique Gonzalez,
14 * Philippe Baumann, Webtoolkit.info (http://www.webtoolkit.info/), Jani
15 * Hartikainen, Ole Vrijenhoek, Ash Searle (http://hexmen.com/blog/), Carlos
16 * R. L. Rodrigues (http://www.jsfromhell.com), travc, Michael Grier,
17 * Erkekjetter, Johnny Mast (http://www.phpvrouwen.nl), Rafa? Kukawski
18 * (http://blog.kukawski.pl/), GeekFG (http://geekfg.blogspot.com), Andrea
19 * Giammarchi (http://webreflection.blogspot.com), WebDevHobo
20 * (http://webdevhobo.blogspot.com/), d3x, marrtins,
21 * http://stackoverflow.com/questions/57803/how-to-convert-decimal-to-hex-in-javascript,
22 * pilus, stag019, T.Wild, Martin (http://www.erlenwiese.de/), majak, Marc
23 * Palau, Mirek Slugen, Chris, Diplom@t (http://difane.com/), Breaking Par
25 * (http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256CFB006C45F7),
26 * gettimeofday, Arpad Ray (mailto:arpad@php.net), Oleg Eremeev, Josh Fraser
27 * (http://onlineaspect.com/2007/06/08/auto-detect-a-time-zone-with-javascript/),
28 * Steve Hilder, mdsjack (http://www.mdsjack.bo.it), Kevin van Zonneveld
29 * (http://kevin.vanzonneveld.net/), gorthaur, Aman Gupta, Sakimori, Joris,
30 * Robin, Kankrelune (http://www.webfaktory.info/), Alfonso Jimenez
31 * (http://www.alfonsojimenez.com), David, Felix Geisendoerfer
32 * (http://www.debuggable.com/felix), Lars Fischer, Karol Kowalski, Imgen Tata
33 * (http://www.myipdf.com/), Steven Levithan (http://blog.stevenlevithan.com),
34 * Tim de Koning (http://www.kingsquare.nl), Dreamer, AJ, Paul Smith, KELAN,
35 * Pellentesque Malesuada, felix, Michael White, Mailfaker
36 * (http://www.weedem.fr/), Thunder.m, Tyler Akins (http://rumkin.com),
37 * saulius, Public Domain (http://www.json.org/json2.js), Caio Ariede
38 * (http://caioariede.com), Steve Clay, David James, madipta, Marco, Ole
39 * Vrijenhoek (http://www.nervous.nl/), class_exists, T. Wild, noname, Arno,
40 * Frank Forte, Francois, Scott Cariss, Slawomir Kaniecki, date, Itsacon
41 * (http://www.itsacon.net/), Billy, vlado houba, Jalal Berrami,
42 * ReverseSyntax, Mateusz "loonquawl" Zalega, john (http://www.jd-tech.net),
43 * mktime, Douglas Crockford (http://javascript.crockford.com), ger, Nick
44 * Kolosov (http://sammy.ru), Nathan, nobbler, Fox, marc andreu, Alex Wilson,
45 * Raphael (Ao RUDLER), Bayron Guevara, Adam Wallner
46 * (http://web2.bitbaro.hu/), paulo kuong, jmweb, Lincoln Ramsay, djmix,
47 * Pyerre, Jon Hohle, Thiago Mata (http://thiagomata.blog.com), lmeyrick
48 * (https://sourceforge.net/projects/bcmath-js/this.), Linuxworld, duncan,
49 * Gilbert, Sanjoy Roy, Shingo, sankai, Oskar Larsson H�gfeldt
50 * (http://oskar-lh.name/), Denny Wardhana, 0m3r, Everlasto, Subhasis Deb,
51 * josh, jd, Pier Paolo Ramon (http://www.mastersoup.com/), P, merabi, Soren
52 * Hansen, EdorFaus, Eugene Bulkin (http://doubleaw.com/), Der Simon
53 * (http://innerdom.sourceforge.net/), echo is bad, JB, LH, kenneth, J A R,
54 * Marc Jansen, Stoyan Kyosev (http://www.svest.org/), Francesco, XoraX
55 * (http://www.xorax.info), Ozh, Brad Touesnard, MeEtc
56 * (http://yass.meetcweb.com), Peter-Paul Koch
57 * (http://www.quirksmode.org/js/beat.html), Olivier Louvignes
58 * (http://mg-crea.com/), T0bsn, Tim Wiel, Bryan Elliott, nord_ua, Martin, JT,
59 * David Randall, Thomas Beaucourt (http://www.webapp.fr), Tim de Koning,
60 * stensi, Pierre-Luc Paour, Kristof Coomans (SCK-CEN Belgian Nucleair
61 * Research Centre), Martin Pool, Kirk Strobeck, Rick Waldron, Brant Messenger
62 * (http://www.brantmessenger.com/), Devan Penner-Woelk, Saulo Vallory, Wagner
63 * B. Soares, Artur Tchernychev, Valentina De Rosa, Jason Wong
64 * (http://carrot.org/), Christoph, Daniel Esteban, strftime, Mick@el, rezna,
65 * Simon Willison (http://simonwillison.net), Anton Ongson, Gabriel Paderni,
66 * Marco van Oort, penutbutterjelly, Philipp Lenssen, Bjorn Roesbeke
67 * (http://www.bjornroesbeke.be/), Bug?, Eric Nagel, Tomasz Wesolowski,
68 * Evertjan Garretsen, Bobby Drake, Blues (http://tech.bluesmoon.info/), Luke
69 * Godfrey, Pul, uestla, Alan C, Ulrich, Rafal Kukawski, Yves Sucaet,
70 * sowberry, Norman "zEh" Fuchs, hitwork, Zahlii, johnrembo, Nick Callen,
71 * Steven Levithan (stevenlevithan.com), ejsanders, Scott Baker, Brian Tafoya
72 * (http://www.premasolutions.com/), Philippe Jausions
73 * (http://pear.php.net/user/jausions), Aidan Lister
74 * (http://aidanlister.com/), Rob, e-mike, HKM, ChaosNo1, metjay, strcasecmp,
75 * strcmp, Taras Bogach, jpfle, Alexander Ermolaev
76 * (http://snippets.dzone.com/user/AlexanderErmolaev), DxGx, kilops, Orlando,
77 * dptr1988, Le Torbi, James (http://www.james-bell.co.uk/), Pedro Tainha
78 * (http://www.pedrotainha.com), James, Arnout Kazemier
79 * (http://www.3rd-Eden.com), Chris McMacken, Yannoo, jakes, gabriel paderni,
80 * FGFEmperor, Greg Frazier, baris ozdil, 3D-GRAF, daniel airton wermann
81 * (http://wermann.com.br), Howard Yeend, Diogo Resende, Allan Jensen
82 * (http://www.winternet.no), Benjamin Lupton, Atli ?�r, Maximusya, davook,
83 * Tod Gentille, Ryan W Tenney (http://ryan.10e.us), Nathan Sepulveda, Cord,
84 * fearphage (http://http/my.opera.com/fearphage/), Victor, Rafa? Kukawski
85 * (http://kukawski.pl), Matteo, Manish, Matt Bradley, Riddler
86 * (http://www.frontierwebdev.com/), Alexander M Beedie, T.J. Leahy, Rafa?
87 * Kukawski, taith, Luis Salazar (http://www.freaky-media.com/), FremyCompany,
88 * Rival, Luke Smith (http://lucassmith.name), Andrej Pavlovic, Garagoth, Le
89 * Torbi (http://www.letorbi.de/), Dino, Josep Sanz (http://www.ws3.es/), rem,
90 * Russell Walker (http://www.nbill.co.uk/), Jamie Beck
91 * (http://www.terabit.ca/), setcookie, Michael, YUI Library:
92 * http://developer.yahoo.com/yui/docs/YAHOO.util.DateLocale.html, Blues at
93 * http://hacks.bluesmoon.info/strftime/strftime.js, Ben
94 * (http://benblume.co.uk/), DtTvB
95 * (http://dt.in.th/2008-09-16.string-length-in-bytes.html), Andreas, William,
96 * meo, incidence, Cagri Ekin, Amirouche, Amir Habibi
97 * (http://www.residence-mixte.com/), Kheang Hok Chin
98 * (http://www.distantia.ca/), Jay Klehr, Lorenzo Pisani, Tony, Yen-Wei Liu,
99 * Greenseed, mk.keck, Leslie Hoare, dude, booeyOH, Ben Bryan
101 * Dual licensed under the MIT (MIT-LICENSE.txt)
102 * and GPL (GPL-LICENSE.txt) licenses.
104 * Permission is hereby granted, free of charge, to any person obtaining a
105 * copy of this software and associated documentation files (the
106 * "Software"), to deal in the Software without restriction, including
107 * without limitation the rights to use, copy, modify, merge, publish,
108 * distribute, sublicense, and/or sell copies of the Software, and to
109 * permit persons to whom the Software is furnished to do so, subject to
110 * the following conditions:
112 * The above copyright notice and this permission notice shall be included
113 * in all copies or substantial portions of the Software.
115 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
116 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
117 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
118 * IN NO EVENT SHALL KEVIN VAN ZONNEVELD BE LIABLE FOR ANY CLAIM, DAMAGES
119 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
120 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
121 * OTHER DEALINGS IN THE SOFTWARE.
124 function htmlentities (string, quote_style, charset, double_encode) {
125 // http://kevin.vanzonneveld.net
126 // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
127 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
128 // + improved by: nobbler
129 // + tweaked by: Jack
130 // + bugfixed by: Onno Marsman
131 // + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
132 // + bugfixed by: Brett Zamir (http://brett-zamir.me)
133 // + input by: Ratheous
134 // + improved by: Rafał Kukawski (http://blog.kukawski.pl)
135 // + improved by: Dj (http://phpjs.org/functions/htmlentities:425#comment_134018)
136 // - depends on: get_html_translation_table
137 // * example 1: htmlentities('Kevin & van Zonneveld');
138 // * returns 1: 'Kevin & van Zonneveld'
139 // * example 2: htmlentities("foo'bar","ENT_QUOTES");
140 // * returns 2: 'foo'bar'
141 var hash_map = this.get_html_translation_table('HTML_ENTITIES', quote_style),
143 string = string == null ? '' : string + '';
149 if (quote_style && quote_style === 'ENT_QUOTES') {
150 hash_map["'"] = ''';
153 if (!!double_encode || double_encode == null) {
154 for (symbol in hash_map) {
155 if (hash_map.hasOwnProperty(symbol)) {
156 string = string.split(symbol).join(hash_map[symbol]);
160 string = string.replace(/([\s\S]*?)(&(?:#\d+|#x[\da-f]+|[a-zA-Z][\da-z]*);|$)/g, function (ignore, text, entity) {
161 for (symbol in hash_map) {
162 if (hash_map.hasOwnProperty(symbol)) {
163 text = text.split(symbol).join(hash_map[symbol]);
167 return text + entity;