PageRenderTime 37ms CodeModel.GetById 2ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 0ms

/reporting/includes/html_entity_decode_php4.php

https://bitbucket.org/meerdevelopersoffice/bolivia
PHP | 343 lines | 273 code | 4 blank | 66 comment | 1 complexity | e1a42f9c6b2d195d2090ce582319dc2c MD5 | raw file
  1<?php
  2//============================================================+
  3// File name   : html_entity_decode_php4.php
  4// Begin       : 2006-06-22
  5// Last Update : 2008-04-01
  6// Author      : Nicola Asuni
  7// Version     : 1.0.000
  8// License     : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
  9// 	----------------------------------------------------------------------------
 10//  Copyright (C) 2002-2008  Nicola Asuni - Tecnick.com S.r.l.
 11// 	
 12// 	This program is free software: you can redistribute it and/or modify
 13// 	it under the terms of the GNU Lesser General Public License as published by
 14// 	the Free Software Foundation, either version 2.1 of the License, or
 15// 	(at your option) any later version.
 16// 	
 17// 	This program is distributed in the hope that it will be useful,
 18// 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 19// 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20// 	GNU Lesser General Public License for more details.
 21// 	
 22// 	You should have received a copy of the GNU Lesser General Public License
 23// 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 24// 	
 25// 	See LICENSE.TXT file for more information.
 26//  ----------------------------------------------------------------------------
 27//
 28//
 29// Description : This is a PHP4 function that redefine the 
 30//               standard html_entity_decode function to support
 31//               UTF-8 encoding.
 32//
 33//
 34// Author: Nicola Asuni
 35//
 36// (c) Copyright:
 37//               Nicola Asuni
 38//               Tecnick.com S.r.l.
 39//               Via della Pace, 11
 40//               09044 Quartucciu (CA)
 41//               ITALY
 42//               www.tecnick.com
 43//               info@tecnick.com
 44//============================================================+
 45
 46/**
 47 * This is a PHP4 function that redefine the standard 
 48 * html_entity_decode function to support UTF-8 encoding.
 49 * @package com.tecnick.tcpdf
 50 * @author Nicola Asuni
 51 * @copyright 2004-2008 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
 52 * @link http://www.tcpdf.org
 53 * @license http://www.gnu.org/copyleft/lesser.html LGPL
 54 */
 55
 56/**
 57 * Returns the UTF-8 string corresponding to unicode value.
 58 * @param $num unicode value to convert.
 59 * @return string converted
 60 */
 61function code_to_utf8($num) {
 62	if ($num <= 0x7F) {
 63		return chr($num);
 64	} elseif ($num <= 0x7FF) {
 65		return chr(($num >> 0x06) + 0xC0).chr(($num & 0x3F) + 128);
 66	} elseif ($num <= 0xFFFF) {
 67		return chr(($num >> 0x0C) + 0xE0).chr((($num >> 0x06) & 0x3F) + 0x80).chr(($num & 0x3F) + 0x80);
 68	} elseif ($num <= 0x1FFFFF) {
 69		return chr(($num >> 0x12) + 0xF0).chr((($num >> 0x0C) & 0x3F) + 0x80).chr((($num >> 0x06) & 0x3F) + 0x80).chr(($num & 0x3F) + 0x80);
 70	}
 71	return ' '; // default value
 72}
 73
 74/**
 75 * Reverse function for htmlentities.
 76 * Convert entities in UTF-8.
 77 * @param $text_to_convert Text to convert.
 78 * @return string converted
 79 */
 80function html_entity_decode_php4($text_to_convert) {
 81	$htmlentities_table = array (
 82		"&Aacute;" => "".chr(195).chr(129)."",
 83		"&aacute;" => "".chr(195).chr(161)."",
 84		"&Acirc;" => "".chr(195).chr(130)."",
 85		"&acirc;" => "".chr(195).chr(162)."",
 86		"&acute;" => "".chr(194).chr(180)."",
 87		"&AElig;" => "".chr(195).chr(134)."",
 88		"&aelig;" => "".chr(195).chr(166)."",
 89		"&Agrave;" => "".chr(195).chr(128)."",
 90		"&agrave;" => "".chr(195).chr(160)."",
 91		"&alefsym;" => "".chr(226).chr(132).chr(181)."",
 92		"&Alpha;" => "".chr(206).chr(145)."",
 93		"&alpha;" => "".chr(206).chr(177)."",
 94		"&amp;" => "".chr(38)."",
 95		"&and;" => "".chr(226).chr(136).chr(167)."",
 96		"&ang;" => "".chr(226).chr(136).chr(160)."",
 97		"&Aring;" => "".chr(195).chr(133)."",
 98		"&aring;" => "".chr(195).chr(165)."",
 99		"&asymp;" => "".chr(226).chr(137).chr(136)."",
100		"&Atilde;" => "".chr(195).chr(131)."",
101		"&atilde;" => "".chr(195).chr(163)."",
102		"&Auml;" => "".chr(195).chr(132)."",
103		"&auml;" => "".chr(195).chr(164)."",
104		"&bdquo;" => "".chr(226).chr(128).chr(158)."",
105		"&Beta;" => "".chr(206).chr(146)."",
106		"&beta;" => "".chr(206).chr(178)."",
107		"&brvbar;" => "".chr(194).chr(166)."",
108		"&bull;" => "".chr(226).chr(128).chr(162)."",
109		"&cap;" => "".chr(226).chr(136).chr(169)."",
110		"&Ccedil;" => "".chr(195).chr(135)."",
111		"&ccedil;" => "".chr(195).chr(167)."",
112		"&cedil;" => "".chr(194).chr(184)."",
113		"&cent;" => "".chr(194).chr(162)."",
114		"&Chi;" => "".chr(206).chr(167)."",
115		"&chi;" => "".chr(207).chr(135)."",
116		"&circ;" => "".chr(203).chr(134)."",
117		"&clubs;" => "".chr(226).chr(153).chr(163)."",
118		"&cong;" => "".chr(226).chr(137).chr(133)."",
119		"&copy;" => "".chr(194).chr(169)."",
120		"&crarr;" => "".chr(226).chr(134).chr(181)."",
121		"&cup;" => "".chr(226).chr(136).chr(170)."",
122		"&curren;" => "".chr(194).chr(164)."",
123		"&dagger;" => "".chr(226).chr(128).chr(160)."",
124		"&Dagger;" => "".chr(226).chr(128).chr(161)."",
125		"&darr;" => "".chr(226).chr(134).chr(147)."",
126		"&dArr;" => "".chr(226).chr(135).chr(147)."",
127		"&deg;" => "".chr(194).chr(176)."",
128		"&Delta;" => "".chr(206).chr(148)."",
129		"&delta;" => "".chr(206).chr(180)."",
130		"&diams;" => "".chr(226).chr(153).chr(166)."",
131		"&divide;" => "".chr(195).chr(183)."",
132		"&Eacute;" => "".chr(195).chr(137)."",
133		"&eacute;" => "".chr(195).chr(169)."",
134		"&Ecirc;" => "".chr(195).chr(138)."",
135		"&ecirc;" => "".chr(195).chr(170)."",
136		"&Egrave;" => "".chr(195).chr(136)."",
137		"&egrave;" => "".chr(195).chr(168)."",
138		"&empty;" => "".chr(226).chr(136).chr(133)."",
139		"&emsp;" => "".chr(226).chr(128).chr(131)."",
140		"&ensp;" => "".chr(226).chr(128).chr(130)."",
141		"&Epsilon;" => "".chr(206).chr(149)."",
142		"&epsilon;" => "".chr(206).chr(181)."",
143		"&equiv;" => "".chr(226).chr(137).chr(161)."",
144		"&Eta;" => "".chr(206).chr(151)."",
145		"&eta;" => "".chr(206).chr(183)."",
146		"&ETH;" => "".chr(195).chr(144)."",
147		"&eth;" => "".chr(195).chr(176)."",
148		"&Euml;" => "".chr(195).chr(139)."",
149		"&euml;" => "".chr(195).chr(171)."",
150		"&euro;" => "".chr(226).chr(130).chr(172)."",
151		"&exist;" => "".chr(226).chr(136).chr(131)."",
152		"&fnof;" => "".chr(198).chr(146)."",
153		"&forall;" => "".chr(226).chr(136).chr(128)."",
154		"&frac12;" => "".chr(194).chr(189)."",
155		"&frac14;" => "".chr(194).chr(188)."",
156		"&frac34;" => "".chr(194).chr(190)."",
157		"&frasl;" => "".chr(226).chr(129).chr(132)."",
158		"&Gamma;" => "".chr(206).chr(147)."",
159		"&gamma;" => "".chr(206).chr(179)."",
160		"&ge;" => "".chr(226).chr(137).chr(165)."",
161		"&harr;" => "".chr(226).chr(134).chr(148)."",
162		"&hArr;" => "".chr(226).chr(135).chr(148)."",
163		"&hearts;" => "".chr(226).chr(153).chr(165)."",
164		"&hellip;" => "".chr(226).chr(128).chr(166)."",
165		"&Iacute;" => "".chr(195).chr(141)."",
166		"&iacute;" => "".chr(195).chr(173)."",
167		"&Icirc;" => "".chr(195).chr(142)."",
168		"&icirc;" => "".chr(195).chr(174)."",
169		"&iexcl;" => "".chr(194).chr(161)."",
170		"&Igrave;" => "".chr(195).chr(140)."",
171		"&igrave;" => "".chr(195).chr(172)."",
172		"&image;" => "".chr(226).chr(132).chr(145)."",
173		"&infin;" => "".chr(226).chr(136).chr(158)."",
174		"&int;" => "".chr(226).chr(136).chr(171)."",
175		"&Iota;" => "".chr(206).chr(153)."",
176		"&iota;" => "".chr(206).chr(185)."",
177		"&iquest;" => "".chr(194).chr(191)."",
178		"&isin;" => "".chr(226).chr(136).chr(136)."",
179		"&Iuml;" => "".chr(195).chr(143)."",
180		"&iuml;" => "".chr(195).chr(175)."",
181		"&Kappa;" => "".chr(206).chr(154)."",
182		"&kappa;" => "".chr(206).chr(186)."",
183		"&Lambda;" => "".chr(206).chr(155)."",
184		"&lambda;" => "".chr(206).chr(187)."",
185		"&lang;" => "".chr(226).chr(140).chr(169)."",
186		"&laquo;" => "".chr(194).chr(171)."",
187		"&larr;" => "".chr(226).chr(134).chr(144)."",
188		"&lArr;" => "".chr(226).chr(135).chr(144)."",
189		"&lceil;" => "".chr(226).chr(140).chr(136)."",
190		"&ldquo;" => "".chr(226).chr(128).chr(156)."",
191		"&le;" => "".chr(226).chr(137).chr(164)."",
192		"&lfloor;" => "".chr(226).chr(140).chr(138)."",
193		"&lowast;" => "".chr(226).chr(136).chr(151)."",
194		"&loz;" => "".chr(226).chr(151).chr(138)."",
195		"&lrm;" => "".chr(226).chr(128).chr(142)."",
196		"&lsaquo;" => "".chr(226).chr(128).chr(185)."",
197		"&lsquo;" => "".chr(226).chr(128).chr(152)."",
198		"&macr;" => "".chr(194).chr(175)."",
199		"&mdash;" => "".chr(226).chr(128).chr(148)."",
200		"&micro;" => "".chr(194).chr(181)."",
201		"&middot;" => "".chr(194).chr(183)."",
202		"&minus;" => "".chr(226).chr(136).chr(146)."",
203		"&Mu;" => "".chr(206).chr(156)."",
204		"&mu;" => "".chr(206).chr(188)."",
205		"&nabla;" => "".chr(226).chr(136).chr(135)."",
206		"&nbsp;" => "".chr(194).chr(160)."",
207		"&ndash;" => "".chr(226).chr(128).chr(147)."",
208		"&ne;" => "".chr(226).chr(137).chr(160)."",
209		"&ni;" => "".chr(226).chr(136).chr(139)."",
210		"&not;" => "".chr(194).chr(172)."",
211		"&notin;" => "".chr(226).chr(136).chr(137)."",
212		"&nsub;" => "".chr(226).chr(138).chr(132)."",
213		"&Ntilde;" => "".chr(195).chr(145)."",
214		"&ntilde;" => "".chr(195).chr(177)."",
215		"&Nu;" => "".chr(206).chr(157)."",
216		"&nu;" => "".chr(206).chr(189)."",
217		"&Oacute;" => "".chr(195).chr(147)."",
218		"&oacute;" => "".chr(195).chr(179)."",
219		"&Ocirc;" => "".chr(195).chr(148)."",
220		"&ocirc;" => "".chr(195).chr(180)."",
221		"&OElig;" => "".chr(197).chr(146)."",
222		"&oelig;" => "".chr(197).chr(147)."",
223		"&Ograve;" => "".chr(195).chr(146)."",
224		"&ograve;" => "".chr(195).chr(178)."",
225		"&oline;" => "".chr(226).chr(128).chr(190)."",
226		"&Omega;" => "".chr(206).chr(169)."",
227		"&omega;" => "".chr(207).chr(137)."",
228		"&Omicron;" => "".chr(206).chr(159)."",
229		"&omicron;" => "".chr(206).chr(191)."",
230		"&oplus;" => "".chr(226).chr(138).chr(149)."",
231		"&or;" => "".chr(226).chr(136).chr(168)."",
232		"&ordf;" => "".chr(194).chr(170)."",
233		"&ordm;" => "".chr(194).chr(186)."",
234		"&Oslash;" => "".chr(195).chr(152)."",
235		"&oslash;" => "".chr(195).chr(184)."",
236		"&Otilde;" => "".chr(195).chr(149)."",
237		"&otilde;" => "".chr(195).chr(181)."",
238		"&otimes;" => "".chr(226).chr(138).chr(151)."",
239		"&Ouml;" => "".chr(195).chr(150)."",
240		"&ouml;" => "".chr(195).chr(182)."",
241		"&para;" => "".chr(194).chr(182)."",
242		"&part;" => "".chr(226).chr(136).chr(130)."",
243		"&permil;" => "".chr(226).chr(128).chr(176)."",
244		"&perp;" => "".chr(226).chr(138).chr(165)."",
245		"&Phi;" => "".chr(206).chr(166)."",
246		"&phi;" => "".chr(207).chr(134)."",
247		"&Pi;" => "".chr(206).chr(160)."",
248		"&pi;" => "".chr(207).chr(128)."",
249		"&piv;" => "".chr(207).chr(150)."",
250		"&plusmn;" => "".chr(194).chr(177)."",
251		"&pound;" => "".chr(194).chr(163)."",
252		"&prime;" => "".chr(226).chr(128).chr(178)."",
253		"&Prime;" => "".chr(226).chr(128).chr(179)."",
254		"&prod;" => "".chr(226).chr(136).chr(143)."",
255		"&prop;" => "".chr(226).chr(136).chr(157)."",
256		"&Psi;" => "".chr(206).chr(168)."",
257		"&psi;" => "".chr(207).chr(136)."",
258		"&radic;" => "".chr(226).chr(136).chr(154)."",
259		"&rang;" => "".chr(226).chr(140).chr(170)."",
260		"&raquo;" => "".chr(194).chr(187)."",
261		"&rarr;" => "".chr(226).chr(134).chr(146)."",
262		"&rArr;" => "".chr(226).chr(135).chr(146)."",
263		"&rceil;" => "".chr(226).chr(140).chr(137)."",
264		"&rdquo;" => "".chr(226).chr(128).chr(157)."",
265		"&real;" => "".chr(226).chr(132).chr(156)."",
266		"&reg;" => "".chr(194).chr(174)."",
267		"&rfloor;" => "".chr(226).chr(140).chr(139)."",
268		"&Rho;" => "".chr(206).chr(161)."",
269		"&rho;" => "".chr(207).chr(129)."",
270		"&rlm;" => "".chr(226).chr(128).chr(143)."",
271		"&rsaquo;" => "".chr(226).chr(128).chr(186)."",
272		"&rsquo;" => "".chr(226).chr(128).chr(153)."",
273		"&sbquo;" => "".chr(226).chr(128).chr(154)."",
274		"&Scaron;" => "".chr(197).chr(160)."",
275		"&scaron;" => "".chr(197).chr(161)."",
276		"&sdot;" => "".chr(226).chr(139).chr(133)."",
277		"&sect;" => "".chr(194).chr(167)."",
278		"&shy;" => "".chr(194).chr(173)."",
279		"&Sigma;" => "".chr(206).chr(163)."",
280		"&sigma;" => "".chr(207).chr(131)."",
281		"&sigmaf;" => "".chr(207).chr(130)."",
282		"&sim;" => "".chr(226).chr(136).chr(188)."",
283		"&spades;" => "".chr(226).chr(153).chr(160)."",
284		"&sub;" => "".chr(226).chr(138).chr(130)."",
285		"&sube;" => "".chr(226).chr(138).chr(134)."",
286		"&sum;" => "".chr(226).chr(136).chr(145)."",
287		"&sup1;" => "".chr(194).chr(185)."",
288		"&sup2;" => "".chr(194).chr(178)."",
289		"&sup3;" => "".chr(194).chr(179)."",
290		"&sup;" => "".chr(226).chr(138).chr(131)."",
291		"&supe;" => "".chr(226).chr(138).chr(135)."",
292		"&szlig;" => "".chr(195).chr(159)."",
293		"&Tau;" => "".chr(206).chr(164)."",
294		"&tau;" => "".chr(207).chr(132)."",
295		"&there4;" => "".chr(226).chr(136).chr(180)."",
296		"&Theta;" => "".chr(206).chr(152)."",
297		"&theta;" => "".chr(206).chr(184)."",
298		"&thetasym;" => "".chr(207).chr(145)."",
299		"&thinsp;" => "".chr(226).chr(128).chr(137)."",
300		"&THORN;" => "".chr(195).chr(158)."",
301		"&thorn;" => "".chr(195).chr(190)."",
302		"&tilde;" => "".chr(203).chr(156)."",
303		"&times;" => "".chr(195).chr(151)."",
304		"&trade;" => "".chr(226).chr(132).chr(162)."",
305		"&Uacute;" => "".chr(195).chr(154)."",
306		"&uacute;" => "".chr(195).chr(186)."",
307		"&uarr;" => "".chr(226).chr(134).chr(145)."",
308		"&uArr;" => "".chr(226).chr(135).chr(145)."",
309		"&Ucirc;" => "".chr(195).chr(155)."",
310		"&ucirc;" => "".chr(195).chr(187)."",
311		"&Ugrave;" => "".chr(195).chr(153)."",
312		"&ugrave;" => "".chr(195).chr(185)."",
313		"&uml;" => "".chr(194).chr(168)."",
314		"&upsih;" => "".chr(207).chr(146)."",
315		"&Upsilon;" => "".chr(206).chr(165)."",
316		"&upsilon;" => "".chr(207).chr(133)."",
317		"&Uuml;" => "".chr(195).chr(156)."",
318		"&uuml;" => "".chr(195).chr(188)."",
319		"&weierp;" => "".chr(226).chr(132).chr(152)."",
320		"&Xi;" => "".chr(206).chr(158)."",
321		"&xi;" => "".chr(206).chr(190)."",
322		"&Yacute;" => "".chr(195).chr(157)."",
323		"&yacute;" => "".chr(195).chr(189)."",
324		"&yen;" => "".chr(194).chr(165)."",
325		"&yuml;" => "".chr(195).chr(191)."",
326		"&Yuml;" => "".chr(197).chr(184)."",
327		"&Zeta;" => "".chr(206).chr(150)."",
328		"&zeta;" => "".chr(206).chr(182)."",
329		"&zwj;" => "".chr(226).chr(128).chr(141)."",
330		"&zwnj;" => "".chr(226).chr(128).chr(140)."",
331		"&gt;" => ">",
332		"&lt;" => "<"
333	);
334	$return_text = strtr($text_to_convert, $htmlentities_table);
335	$return_text = preg_replace('~&#x([0-9a-f]+);~ei', 'code_to_utf8(hexdec("\\1"))', $return_text);
336	$return_text = preg_replace('~&#([0-9]+);~e', 'code_to_utf8(\\1)', $return_text);
337	return $return_text;
338}
339
340//============================================================+
341// END OF FILE
342//============================================================+
343?>