5 function named_to_numeric ($string) {
6 $string = preg_replace('/(&[0-9A-Za-z]+)(;?\=?|([^A-Za-z0-9\;\:\.\-\_]))/e', "entity::_named('\\1', '\\2') . '\\3'", $string);
10 function normalize_numeric ($string) {
12 $string = preg_replace('/&#([0-9]+)(;)?/e', "'&#x'.dechex('\\1').';'", $string);
13 $string = preg_replace('/&#[Xx](0)*([0-9A-Fa-f]+)(;?|([^A-Za-z0-9\;\:\.\-\_]))/e', "'&#x' . strtoupper('\\2') . ';\\4'", $string);
14 $string = strtr($string, $_entities['cp1251']);
18 function numeric_to_utf8 ($string) {
19 $string = preg_replace('/&#([0-9]+)(;)?/e', "'&#x'.dechex('\\1').';'", $string);
20 $string = preg_replace('/&#[Xx](0)*([0-9A-Fa-f]+)(;?|([^A-Za-z0-9\;\:\.\-\_]))/e', "'&#x' . strtoupper('\\2') . ';\\4'", $string);
21 $string = preg_replace('/&#x([0-9A-Fa-f]+);/e', "entity::_hex_to_utf8('\\1')", $string);
25 function numeric_to_named ($string) {
27 $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+)/e', "'&#'.hexdec('\\1')", $string);
28 $string = strtr($string, array_flip($_entities['named']));
32 function specialchars ($string, $type = 'xml') {
33 $apos = $type == 'xml' ? ''' : ''';
34 $specialchars = array (
35 '"' => '"', '&' => '&',
36 ''' => $apos, '<' => '<',
37 '>' => '>', '"' => '"',
38 '&' => '&', "'" => $apos,
39 '<' => '<', '>' => '>'
42 $string = preg_replace('/&(#?[Xx]?[0-9A-Za-z]+);/', "[[[ENTITY:\\1]]]", $string);
43 $string = strtr($string, $specialchars);
44 $string = preg_replace('/\[\[\[ENTITY\:([^\]]+)\]\]\]/', "&\\1;", $string);
49 function _hex_to_utf8($s)
56 else if ($c < 0x800) {
57 $str = chr(0xC0 | $c>>6) . chr(0x80 | $c & 0x3F);
59 else if ($c < 0x10000) {
60 $str = chr(0xE0 | $c>>12) . chr(0x80 | $c>>6 & 0x3F) . chr(0x80 | $c & 0x3F);
62 else if ($c < 0x200000) {
63 $str = chr(0xF0 | $c>>18) . chr(0x80 | $c>>12 & 0x3F) . chr(0x80 | $c>>6 & 0x3F) . chr(0x80 | $c & 0x3F);
69 function _named($entity, $extra) {
72 if ($extra == '=') return $entity . '=';
74 $length = strlen($entity);
77 $check = substr($entity, 0, $length);
78 if (isset($_entities['named'][$check])) return $_entities['named'][$check] . ';' . substr($entity, $length);
82 return $entity . ($extra == ';' ? ';' : '');
87 $_entities['cp1251'] = array (
88 '€' => '€', '‚' => '‚', 'ƒ' => 'ƒ',
89 '„' => '„', '…' => '…', '†' => '†',
90 '‡' => '‡', 'ˆ' => 'ˆ', '‰' => '‰',
91 'Š' => 'Š', '‹' => '‹', 'Œ' => 'Œ',
92 'Ž' => 'Ž', '‘' => '‘', '’' => '’',
93 '“' => '“', '”' => '”', '•' => '•',
94 '–' => '–', '—' => '—', '˜' => '˜',
95 '™' => '™', 'š' => 'š', '›' => '›',
96 'œ' => 'œ', 'ž' => 'ž', 'Ÿ' => 'Ÿ',
99 $_entities['named'] = array (
100 ' ' => ' ', '¡' => '¡', '¢' => '¢',
101 '£' => '£', '¤' => '¤', '¥' => '¥',
102 '¦' => '¦', '§' => '§', '¨' => '¨',
103 '©' => '©', 'ª' => 'ª', '«' => '«',
104 '¬' => '¬', '­' => '­', '®' => '®',
105 '¯' => '¯', '°' => '°', '±' => '±',
106 '²' => '²', '³' => '³', '´' => '´',
107 'µ' => 'µ', '¶' => '¶', '·' => '·',
108 '¸' => '¸', '¹' => '¹', 'º' => 'º',
109 '»' => '»', '¼' => '¼', '½' => '½',
110 '¾' => '¾', '¿' => '¿', 'À' => 'À',
111 'Á' => 'Á', 'Â' => 'Â', 'Ã' => 'Ã',
112 'Ä' => 'Ä', 'Å' => 'Å', 'Æ' => 'Æ',
113 'Ç' => 'Ç', 'È' => 'È', 'É' => 'É',
114 'Ê' => 'Ê', 'Ë' => 'Ë', 'Ì' => 'Ì',
115 'Í' => 'Í', 'Î' => 'Î', 'Ï' => 'Ï',
116 'Ð' => 'Ð', 'Ñ' => 'Ñ', 'Ò' => 'Ò',
117 'Ó' => 'Ó', 'Ô' => 'Ô', 'Õ' => 'Õ',
118 'Ö' => 'Ö', '×' => '×', 'Ø' => 'Ø',
119 'Ù' => 'Ù', 'Ú' => 'Ú', 'Û' => 'Û',
120 'Ü' => 'Ü', 'Ý' => 'Ý', 'Þ' => 'Þ',
121 'ß' => 'ß', 'à' => 'à', 'á' => 'á',
122 'â' => 'â', 'ã' => 'ã', 'ä' => 'ä',
123 'å' => 'å', 'æ' => 'æ', 'ç' => 'ç',
124 'è' => 'è', 'é' => 'é', 'ê' => 'ê',
125 'ë' => 'ë', 'ì' => 'ì', 'í' => 'í',
126 'î' => 'î', 'ï' => 'ï', 'ð' => 'ð',
127 'ñ' => 'ñ', 'ò' => 'ò', 'ó' => 'ó',
128 'ô' => 'ô', 'õ' => 'õ', 'ö' => 'ö',
129 '÷' => '÷', 'ø' => 'ø', 'ù' => 'ù',
130 'ú' => 'ú', 'û' => 'û', 'ü' => 'ü',
131 'ý' => 'ý', 'þ' => 'þ', 'ÿ' => 'ÿ',
132 '&OElig' => 'Œ', '&oelig' => 'å', '&Scaron' => 'Š',
133 '&scaron' => 'š', '&Yuml' => 'Ÿ', '&circ' => 'ˆ',
134 '&tilde' => '˜', '&esnp' => ' ', '&emsp' => ' ',
135 '&thinsp' => ' ', '&zwnj' => '‌', '&zwj' => '‍',
136 '&lrm' => '‎', '&rlm' => '‏', '&ndash' => '–',
137 '&mdash' => '—', '&lsquo' => '‘', '&rsquo' => '’',
138 '&sbquo' => '‚', '&ldquo' => '“', '&rdquo' => '”',
139 '&bdquo' => '„', '&dagger' => '†', '&Dagger' => '‡',
140 '&permil' => '‰', '&lsaquo' => '‹', '&rsaquo' => '›',
141 '&euro' => '€', '&fnof' => 'ƒ', '&Alpha' => 'Α',
142 '&Beta' => 'Β', '&Gamma' => 'Γ', '&Delta' => 'Δ',
143 '&Epsilon' => 'Ε', '&Zeta' => 'Ζ', '&Eta' => 'Η',
144 '&Theta' => 'Θ', '&Iota' => 'Ι', '&Kappa' => 'Κ',
145 '&Lambda' => 'Λ', '&Mu' => 'Μ', '&Nu' => 'Ν',
146 '&Xi' => 'Ξ', '&Omicron' => 'Ο', '&Pi' => 'Π',
147 '&Rho' => 'Ρ', '&Sigma' => 'Σ', '&Tau' => 'Τ',
148 '&Upsilon' => 'Υ', '&Phi' => 'Φ', '&Chi' => 'Χ',
149 '&Psi' => 'Ψ', '&Omega' => 'Ω', '&alpha' => 'α',
150 '&beta' => 'β', '&gamma' => 'γ', '&delta' => 'δ',
151 '&epsilon' => 'ε', '&zeta' => 'ζ', '&eta' => 'η',
152 '&theta' => 'θ', '&iota' => 'ι', '&kappa' => 'κ',
153 '&lambda' => 'λ', '&mu' => 'μ', '&nu' => 'ν',
154 '&xi' => 'ξ', '&omicron' => 'ο', '&pi' => 'π',
155 '&rho' => 'ρ', '&sigmaf' => 'ς', '&sigma' => 'σ',
156 '&tau' => 'τ', '&upsilon' => 'υ', '&phi' => 'φ',
157 '&chi' => 'χ', '&psi' => 'ψ', '&omega' => 'ω',
158 '&thetasym' => 'ϑ', '&upsih' => 'ϒ', '&piv' => 'ϖ',
159 '&bull' => '•', '&hellip' => '…', '&prime' => '′',
160 '&Prime' => '″', '&oline' => '‾', '&frasl' => '⁄',
161 '&weierp' => '℘', '&image' => 'ℑ', '&real' => 'ℜ',
162 '&trade' => '™', '&alefsym' => 'ℵ', '&larr' => '←',
163 '&uarr' => '↑', '&rarr' => '→', '&darr' => '↓',
164 '&harr' => '↔', '&crarr' => '↵', '&lArr' => '⇐',
165 '&uArr' => '⇑', '&rArr' => '⇒', '&dArr' => '⇓',
166 '&hArr' => '⇔', '&forall' => '∀', '&part' => '∂',
167 '&exist' => '∃', '&empty' => '∅', '&nabla' => '∇',
168 '&isin' => '∈', '¬in' => '∉', '&ni' => '∋',
169 '&prod' => '∏', '&sum' => '∑', '&minus' => '−',
170 '&lowast' => '∗', '&radic' => '√', '&prop' => '∝',
171 '&infin' => '∞', '&ang' => '∠', '&and' => '∧',
172 '&or' => '∨', '&cap' => '∩', '&cup' => '∪',
173 '&int' => '∫', '&there4' => '∴', '&sim' => '∼',
174 '&cong' => '≅', '&asymp' => '≈', '&ne' => '≠',
175 '&equiv' => '≡', '&le' => '≤', '&ge' => '≥',
176 '&sub' => '⊂', '&sup' => '⊃', '&nsub' => '⊄',
177 '&sube' => '⊆', '&supe' => '⊇', '&oplus' => '⊕',
178 '&otimes' => '⊗', '&perp' => '⊥', '&sdot' => '⋅',
179 '&lceil' => '⌈', '&rceil' => '⌉', '&lfloor' => '⌊',
180 '&rfloor' => '⌋', '&lang' => '〈', '&rang' => '〉',
181 '&loz' => '◊', '&spades' => '♠', '&clubs' => '♣',
182 '&hearts' => '♥', '&diams' => '♦',