31721903dfa8b998f8190a2f02b5503b95020eb7
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file contains variuos functions that are needed to do
10 * internationalization of SquirrelMail.
12 * Internally the output character set is used. Other characters are
13 * encoded using Unicode entities according to HTML 4.0.
18 /* Decodes a string to the internal encoding from the given charset */
19 function charset_decode ($charset, $string) {
20 global $languages, $squirrelmail_language;
22 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
23 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
24 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
27 /* All HTML special characters are 7 bit and can be replaced first */
28 $string = htmlspecialchars ($string);
30 $charset = strtolower($charset);
34 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
36 $ret = charset_decode_iso_8859_1 ($string);
37 } else if ($res[1] == '2') {
38 $ret = charset_decode_iso_8859_2 ($string);
39 } else if ($res[1] == '4') {
40 $ret = charset_decode_iso_8859_4 ($string);
41 } else if ($res[1] == '5') {
42 $ret = charset_decode_iso_8859_5 ($string);
43 } else if ($res[1] == '7') {
44 $ret = charset_decode_iso_8859_7 ($string);
45 } else if ($res[1] == '9') {
46 $ret = charset_decode_iso_8859_9 ($string);
47 } else if ($res[1] == '13') {
48 $ret = charset_decode_iso_8859_13 ($string);
49 } else if ($res[1] == '15') {
50 $ret = charset_decode_iso_8859_15 ($string);
52 $ret = charset_decode_iso_8859_default ($string);
54 } else if ($charset == 'ns_4551-1') {
55 $ret = charset_decode_ns_4551_1 ($string);
56 } else if ($charset == 'koi8-r') {
57 $ret = charset_decode_koi8r ($string);
58 } else if ($charset == 'windows-1251') {
59 $ret = charset_decode_windows_1251 ($string);
60 } else if ($charset == 'windows-1253') {
61 $ret = charset_decode_windows_1253 ($string);
62 } else if ($charset == 'windows-1254') {
63 $ret = charset_decode_windows_1254 ($string);
64 } else if ($charset == 'windows-1257') {
65 $ret = charset_decode_windows_1257 ($string);
66 } else if ($charset == 'utf-8') {
67 $ret = charset_decode_utf8 ($string);
75 iso-8859-1 is the same as Latin 1 and is normally used
78 function charset_decode_iso_8859_1 ($string) {
79 global $default_charset;
81 if (strtolower($default_charset) <> 'iso-8859-1') {
82 /* Only do the slow convert if there are 8-bit characters */
83 if (ereg("[\200-\377]", $string)) {
84 $string = str_replace("\201", '', $string);
85 $string = str_replace("\202", '‚', $string);
86 $string = str_replace("\203", 'ƒ', $string);
87 $string = str_replace("\204", '„', $string);
88 $string = str_replace("\205", '…', $string);
89 $string = str_replace("\206", '†', $string);
90 $string = str_replace("\207", '‡', $string);
91 $string = str_replace("\210", 'ˆ', $string);
92 $string = str_replace("\211", '‰', $string);
93 $string = str_replace("\212", 'Š', $string);
94 $string = str_replace("\213", '‹', $string);
95 $string = str_replace("\214", 'Œ', $string);
96 $string = str_replace("\215", '', $string);
97 $string = str_replace("\216", 'Ž', $string);
98 $string = str_replace("\217", '', $string);
99 $string = str_replace("\220", '', $string);
100 $string = str_replace("\221", '‘', $string);
101 $string = str_replace("\222", '’', $string);
102 $string = str_replace("\223", '“', $string);
103 $string = str_replace("\224", '”', $string);
104 $string = str_replace("\225", '•', $string);
105 $string = str_replace("\226", '–', $string);
106 $string = str_replace("\227", '—', $string);
107 $string = str_replace("\230", '˜', $string);
108 $string = str_replace("\231", '™', $string);
109 $string = str_replace("\232", 'š', $string);
110 $string = str_replace("\233", '›', $string);
111 $string = str_replace("\234", 'œ', $string);
112 $string = str_replace("\235", '', $string);
113 $string = str_replace("\236", 'ž', $string);
114 $string = str_replace("\237", 'Ÿ', $string);
115 $string = str_replace("\240", ' ', $string);
116 $string = str_replace("\241", '¡', $string);
117 $string = str_replace("\242", '¢', $string);
118 $string = str_replace("\243", '£', $string);
119 $string = str_replace("\244", '¤', $string);
120 $string = str_replace("\245", '¥', $string);
121 $string = str_replace("\246", '¦', $string);
122 $string = str_replace("\247", '§', $string);
123 $string = str_replace("\250", '¨', $string);
124 $string = str_replace("\251", '©', $string);
125 $string = str_replace("\252", 'ª', $string);
126 $string = str_replace("\253", '«', $string);
127 $string = str_replace("\254", '¬', $string);
128 $string = str_replace("\255", '­', $string);
129 $string = str_replace("\256", '®', $string);
130 $string = str_replace("\257", '¯', $string);
131 $string = str_replace("\260", '°', $string);
132 $string = str_replace("\261", '±', $string);
133 $string = str_replace("\262", '²', $string);
134 $string = str_replace("\263", '³', $string);
135 $string = str_replace("\264", '´', $string);
136 $string = str_replace("\265", 'µ', $string);
137 $string = str_replace("\266", '¶', $string);
138 $string = str_replace("\267", '·', $string);
139 $string = str_replace("\270", '¸', $string);
140 $string = str_replace("\271", '¹', $string);
141 $string = str_replace("\272", 'º', $string);
142 $string = str_replace("\273", '»', $string);
143 $string = str_replace("\274", '¼', $string);
144 $string = str_replace("\275", '½', $string);
145 $string = str_replace("\276", '¾', $string);
146 $string = str_replace("\277", '¿', $string);
147 $string = str_replace("\300", 'À', $string);
148 $string = str_replace("\301", 'Á', $string);
149 $string = str_replace("\302", 'Â', $string);
150 $string = str_replace("\303", 'Ã', $string);
151 $string = str_replace("\304", 'Ä', $string);
152 $string = str_replace("\305", 'Å', $string);
153 $string = str_replace("\306", 'Æ', $string);
154 $string = str_replace("\307", 'Ç', $string);
155 $string = str_replace("\310", 'È', $string);
156 $string = str_replace("\311", 'É', $string);
157 $string = str_replace("\312", 'Ê', $string);
158 $string = str_replace("\313", 'Ë', $string);
159 $string = str_replace("\314", 'Ì', $string);
160 $string = str_replace("\315", 'Í', $string);
161 $string = str_replace("\316", 'Î', $string);
162 $string = str_replace("\317", 'Ï', $string);
163 $string = str_replace("\320", 'Ð', $string);
164 $string = str_replace("\321", 'Ñ', $string);
165 $string = str_replace("\322", 'Ò', $string);
166 $string = str_replace("\323", 'Ó', $string);
167 $string = str_replace("\324", 'Ô', $string);
168 $string = str_replace("\325", 'Õ', $string);
169 $string = str_replace("\326", 'Ö', $string);
170 $string = str_replace("\327", '×', $string);
171 $string = str_replace("\330", 'Ø', $string);
172 $string = str_replace("\331", 'Ù', $string);
173 $string = str_replace("\332", 'Ú', $string);
174 $string = str_replace("\333", 'Û', $string);
175 $string = str_replace("\334", 'Ü', $string);
176 $string = str_replace("\335", 'Ý', $string);
177 $string = str_replace("\336", 'Þ', $string);
178 $string = str_replace("\337", 'ß', $string);
179 $string = str_replace("\340", 'à', $string);
180 $string = str_replace("\341", 'á', $string);
181 $string = str_replace("\342", 'â', $string);
182 $string = str_replace("\343", 'ã', $string);
183 $string = str_replace("\344", 'ä', $string);
184 $string = str_replace("\345", 'å', $string);
185 $string = str_replace("\346", 'æ', $string);
186 $string = str_replace("\347", 'ç', $string);
187 $string = str_replace("\350", 'è', $string);
188 $string = str_replace("\351", 'é', $string);
189 $string = str_replace("\352", 'ê', $string);
190 $string = str_replace("\353", 'ë', $string);
191 $string = str_replace("\354", 'ì', $string);
192 $string = str_replace("\355", 'í', $string);
193 $string = str_replace("\356", 'î', $string);
194 $string = str_replace("\357", 'ï', $string);
195 $string = str_replace("\360", 'ð', $string);
196 $string = str_replace("\361", 'ñ', $string);
197 $string = str_replace("\362", 'ò', $string);
198 $string = str_replace("\363", 'ó', $string);
199 $string = str_replace("\364", 'ô', $string);
200 $string = str_replace("\365", 'õ', $string);
201 $string = str_replace("\366", 'ö', $string);
202 $string = str_replace("\367", '÷', $string);
203 $string = str_replace("\370", 'ø', $string);
204 $string = str_replace("\371", 'ù', $string);
205 $string = str_replace("\372", 'ú', $string);
206 $string = str_replace("\373", 'û', $string);
207 $string = str_replace("\374", 'ü', $string);
208 $string = str_replace("\375", 'ý', $string);
209 $string = str_replace("\376", 'þ', $string);
210 $string = str_replace("\377", 'ÿ', $string);
217 /* iso-8859-2 is used for some eastern European languages */
218 function charset_decode_iso_8859_2 ($string) {
219 global $default_charset;
221 if (strtolower($default_charset) == 'iso-8859-2')
224 /* Only do the slow convert if there are 8-bit characters */
225 if (! ereg("[\200-\377]", $string))
229 $string = str_replace("\240", ' ', $string);
230 /* LATIN CAPITAL LETTER A WITH OGONEK */
231 $string = str_replace("\241", 'Ą', $string);
233 $string = str_replace("\242", '˘', $string);
234 // LATIN CAPITAL LETTER L WITH STROKE
235 $string = str_replace("\243", 'Ł', $string);
237 $string = str_replace("\244", '¤', $string);
238 // LATIN CAPITAL LETTER L WITH CARON
239 $string = str_replace("\245", 'Ľ', $string);
240 // LATIN CAPITAL LETTER S WITH ACUTE
241 $string = str_replace("\246", 'Ś', $string);
243 $string = str_replace("\247", '§', $string);
245 $string = str_replace("\250", '¨', $string);
246 // LATIN CAPITAL LETTER S WITH CARON
247 $string = str_replace("\251", 'Š', $string);
248 // LATIN CAPITAL LETTER S WITH CEDILLA
249 $string = str_replace("\252", 'Ş', $string);
250 // LATIN CAPITAL LETTER T WITH CARON
251 $string = str_replace("\253", 'Ť', $string);
252 // LATIN CAPITAL LETTER Z WITH ACUTE
253 $string = str_replace("\254", 'Ź', $string);
255 $string = str_replace("\255", '­', $string);
256 // LATIN CAPITAL LETTER Z WITH CARON
257 $string = str_replace("\256", 'Ž', $string);
258 // LATIN CAPITAL LETTER Z WITH DOT ABOVE
259 $string = str_replace("\257", 'Ż', $string);
261 $string = str_replace("\260", '°', $string);
262 // LATIN SMALL LETTER A WITH OGONEK
263 $string = str_replace("\261", 'ą', $string);
265 $string = str_replace("\262", '˛', $string);
266 // LATIN SMALL LETTER L WITH STROKE
267 $string = str_replace("\263", 'ł', $string);
269 $string = str_replace("\264", '´', $string);
270 // LATIN SMALL LETTER L WITH CARON
271 $string = str_replace("\265", 'ľ', $string);
272 // LATIN SMALL LETTER S WITH ACUTE
273 $string = str_replace("\266", 'ś', $string);
275 $string = str_replace("\267", 'ˇ', $string);
277 $string = str_replace("\270", '¸', $string);
278 // LATIN SMALL LETTER S WITH CARON
279 $string = str_replace("\271", 'š', $string);
280 // LATIN SMALL LETTER S WITH CEDILLA
281 $string = str_replace("\272", 'ş', $string);
282 // LATIN SMALL LETTER T WITH CARON
283 $string = str_replace("\273", 'ť', $string);
284 // LATIN SMALL LETTER Z WITH ACUTE
285 $string = str_replace("\274", 'ź', $string);
286 // DOUBLE ACUTE ACCENT
287 $string = str_replace("\275", '˝', $string);
288 // LATIN SMALL LETTER Z WITH CARON
289 $string = str_replace("\276", 'ž', $string);
290 // LATIN SMALL LETTER Z WITH DOT ABOVE
291 $string = str_replace("\277", 'ż', $string);
292 // LATIN CAPITAL LETTER R WITH ACUTE
293 $string = str_replace("\300", 'Ŕ', $string);
294 // LATIN CAPITAL LETTER A WITH ACUTE
295 $string = str_replace("\301", 'Á', $string);
296 // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
297 $string = str_replace("\302", 'Â', $string);
298 // LATIN CAPITAL LETTER A WITH BREVE
299 $string = str_replace("\303", 'Ă', $string);
300 // LATIN CAPITAL LETTER A WITH DIAERESIS
301 $string = str_replace("\304", 'Ä', $string);
302 // LATIN CAPITAL LETTER L WITH ACUTE
303 $string = str_replace("\305", 'Ĺ', $string);
304 // LATIN CAPITAL LETTER C WITH ACUTE
305 $string = str_replace("\306", 'Ć', $string);
306 // LATIN CAPITAL LETTER C WITH CEDILLA
307 $string = str_replace("\307", 'Ç', $string);
308 // LATIN CAPITAL LETTER C WITH CARON
309 $string = str_replace("\310", 'Č', $string);
310 // LATIN CAPITAL LETTER E WITH ACUTE
311 $string = str_replace("\311", 'É', $string);
312 // LATIN CAPITAL LETTER E WITH OGONEK
313 $string = str_replace("\312", 'Ę', $string);
314 // LATIN CAPITAL LETTER E WITH DIAERESIS
315 $string = str_replace("\313", 'Ë', $string);
316 // LATIN CAPITAL LETTER E WITH CARON
317 $string = str_replace("\314", 'Ě', $string);
318 // LATIN CAPITAL LETTER I WITH ACUTE
319 $string = str_replace("\315", 'Í', $string);
320 // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
321 $string = str_replace("\316", 'Î', $string);
322 // LATIN CAPITAL LETTER D WITH CARON
323 $string = str_replace("\317", 'Ď', $string);
324 // LATIN CAPITAL LETTER D WITH STROKE
325 $string = str_replace("\320", 'Đ', $string);
326 // LATIN CAPITAL LETTER N WITH ACUTE
327 $string = str_replace("\321", 'Ń', $string);
328 // LATIN CAPITAL LETTER N WITH CARON
329 $string = str_replace("\322", 'Ň', $string);
330 // LATIN CAPITAL LETTER O WITH ACUTE
331 $string = str_replace("\323", 'Ó', $string);
332 // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
333 $string = str_replace("\324", 'Ô', $string);
334 // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
335 $string = str_replace("\325", 'Ő', $string);
336 // LATIN CAPITAL LETTER O WITH DIAERESIS
337 $string = str_replace("\326", 'Ö', $string);
338 // MULTIPLICATION SIGN
339 $string = str_replace("\327", '×', $string);
340 // LATIN CAPITAL LETTER R WITH CARON
341 $string = str_replace("\330", 'Ř', $string);
342 // LATIN CAPITAL LETTER U WITH RING ABOVE
343 $string = str_replace("\331", 'Ů', $string);
344 // LATIN CAPITAL LETTER U WITH ACUTE
345 $string = str_replace("\332", 'Ú', $string);
346 // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
347 $string = str_replace("\333", 'Ű', $string);
348 // LATIN CAPITAL LETTER U WITH DIAERESIS
349 $string = str_replace("\334", 'Ü', $string);
350 // LATIN CAPITAL LETTER Y WITH ACUTE
351 $string = str_replace("\335", 'Ý', $string);
352 // LATIN CAPITAL LETTER T WITH CEDILLA
353 $string = str_replace("\336", 'Ţ', $string);
354 // LATIN SMALL LETTER SHARP S
355 $string = str_replace("\337", 'ß', $string);
356 // LATIN SMALL LETTER R WITH ACUTE
357 $string = str_replace("\340", 'ŕ', $string);
358 // LATIN SMALL LETTER A WITH ACUTE
359 $string = str_replace("\341", 'á', $string);
360 // LATIN SMALL LETTER A WITH CIRCUMFLEX
361 $string = str_replace("\342", 'â', $string);
362 // LATIN SMALL LETTER A WITH BREVE
363 $string = str_replace("\343", 'ă', $string);
364 // LATIN SMALL LETTER A WITH DIAERESIS
365 $string = str_replace("\344", 'ä', $string);
366 // LATIN SMALL LETTER L WITH ACUTE
367 $string = str_replace("\345", 'ĺ', $string);
368 // LATIN SMALL LETTER C WITH ACUTE
369 $string = str_replace("\346", 'ć', $string);
370 // LATIN SMALL LETTER C WITH CEDILLA
371 $string = str_replace("\347", 'ç', $string);
372 // LATIN SMALL LETTER C WITH CARON
373 $string = str_replace("\350", 'č', $string);
374 // LATIN SMALL LETTER E WITH ACUTE
375 $string = str_replace("\351", 'é', $string);
376 // LATIN SMALL LETTER E WITH OGONEK
377 $string = str_replace("\352", 'ę', $string);
378 // LATIN SMALL LETTER E WITH DIAERESIS
379 $string = str_replace("\353", 'ë', $string);
380 // LATIN SMALL LETTER E WITH CARON
381 $string = str_replace("\354", 'ě', $string);
382 // LATIN SMALL LETTER I WITH ACUTE
383 $string = str_replace("\355", 'í', $string);
384 // LATIN SMALL LETTER I WITH CIRCUMFLEX
385 $string = str_replace("\356", 'î', $string);
386 // LATIN SMALL LETTER D WITH CARON
387 $string = str_replace("\357", 'ď', $string);
388 // LATIN SMALL LETTER D WITH STROKE
389 $string = str_replace("\360", 'đ', $string);
390 // LATIN SMALL LETTER N WITH ACUTE
391 $string = str_replace("\361", 'ń', $string);
392 // LATIN SMALL LETTER N WITH CARON
393 $string = str_replace("\362", 'ň', $string);
394 // LATIN SMALL LETTER O WITH ACUTE
395 $string = str_replace("\363", 'ó', $string);
396 // LATIN SMALL LETTER O WITH CIRCUMFLEX
397 $string = str_replace("\364", 'ô', $string);
398 // LATIN SMALL LETTER O WITH DOUBLE ACUTE
399 $string = str_replace("\365", 'ő', $string);
400 // LATIN SMALL LETTER O WITH DIAERESIS
401 $string = str_replace("\366", 'ö', $string);
403 $string = str_replace("\367", '÷', $string);
404 // LATIN SMALL LETTER R WITH CARON
405 $string = str_replace("\370", 'ř', $string);
406 // LATIN SMALL LETTER U WITH RING ABOVE
407 $string = str_replace("\371", 'ů', $string);
408 // LATIN SMALL LETTER U WITH ACUTE
409 $string = str_replace("\372", 'ú', $string);
410 // LATIN SMALL LETTER U WITH DOUBLE ACUTE
411 $string = str_replace("\373", 'ű', $string);
412 // LATIN SMALL LETTER U WITH DIAERESIS
413 $string = str_replace("\374", 'ü', $string);
414 // LATIN SMALL LETTER Y WITH ACUTE
415 $string = str_replace("\375", 'ý', $string);
416 // LATIN SMALL LETTER T WITH CEDILLA
417 $string = str_replace("\376", 'ţ', $string);
419 $string = str_replace("\377", '˙', $string);
425 ISO/IEC 8859-4:1998 Latin Alphabet No. 4
428 function charset_decode_iso_8859_4 ($string) {
429 global $default_charset;
431 if (strtolower($default_charset) == 'iso-8859-4')
434 /* Only do the slow convert if there are 8-bit characters */
435 if (! ereg("[\200-\377]", $string))
438 $string = str_replace ("\241", 'Ą', $string);
439 $string = str_replace ("\242", 'ĸ', $string);
440 $string = str_replace ("\243", 'Ŗ', $string);
441 $string = str_replace ("\245", 'Ĩ', $string);
442 $string = str_replace ("\246", 'Ļ', $string);
443 $string = str_replace ("\251", 'Š', $string);
444 $string = str_replace ("\252", 'Ē', $string);
445 $string = str_replace ("\253", 'Ģ', $string);
446 $string = str_replace ("\254", 'Ŧ', $string);
447 $string = str_replace ("\256", 'Ž', $string);
448 $string = str_replace ("\261", 'ą', $string);
449 $string = str_replace ("\262", '˛', $string);
450 $string = str_replace ("\263", 'ŗ', $string);
451 $string = str_replace ("\265", 'ĩ', $string);
452 $string = str_replace ("\266", 'ļ', $string);
453 $string = str_replace ("\267", 'ˇ', $string);
454 $string = str_replace ("\271", 'š', $string);
455 $string = str_replace ("\272", 'ē', $string);
456 $string = str_replace ("\273", 'ģ', $string);
457 $string = str_replace ("\274", 'ŧ', $string);
458 $string = str_replace ("\275", 'Ŋ', $string);
459 $string = str_replace ("\276", 'ž', $string);
460 $string = str_replace ("\277", 'ŋ', $string);
461 $string = str_replace ("\300", 'Ā', $string);
462 $string = str_replace ("\307", 'Į', $string);
463 $string = str_replace ("\310", 'Č', $string);
464 $string = str_replace ("\312", 'Ę', $string);
465 $string = str_replace ("\314", 'Ė', $string);
466 $string = str_replace ("\317", 'Ī', $string);
467 $string = str_replace ("\320", 'Đ', $string);
468 $string = str_replace ("\321", 'Ņ', $string);
469 $string = str_replace ("\322", 'Ō', $string);
470 $string = str_replace ("\323", 'Ķ', $string);
471 $string = str_replace ("\331", 'Ų', $string);
472 $string = str_replace ("\335", 'Ũ', $string);
473 $string = str_replace ("\336", 'Ū', $string);
474 $string = str_replace ("\340", 'ā', $string);
475 $string = str_replace ("\347", 'į', $string);
476 $string = str_replace ("\350", 'č', $string);
477 $string = str_replace ("\352", 'ę', $string);
478 $string = str_replace ("\354", 'ė', $string);
479 $string = str_replace ("\357", 'ī', $string);
480 $string = str_replace ("\360", 'đ', $string);
481 $string = str_replace ("\361", 'ņ', $string);
482 $string = str_replace ("\362", 'ō', $string);
483 $string = str_replace ("\363", 'ķ', $string);
484 $string = str_replace ("\371", 'ų', $string);
485 $string = str_replace ("\375", 'ũ', $string);
486 $string = str_replace ("\376", 'ū', $string);
487 $string = str_replace ("\377", '˙', $string);
489 // rest of charset is the same as ISO-8859-1
490 return (charset_decode_iso_8859_1($string));
493 /* iso-8859-7 is Greek. */
494 function charset_decode_iso_8859_7 ($string) {
495 global $default_charset;
497 if (strtolower($default_charset) == 'iso-8859-7') {
501 /* Only do the slow convert if there are 8-bit characters */
502 if (!ereg("[\200-\377]", $string)) {
506 /* Some diverse characters in the beginning */
507 $string = str_replace("\240", ' ', $string);
508 $string = str_replace("\241", '‘', $string);
509 $string = str_replace("\242", '’', $string);
510 $string = str_replace("\243", '£', $string);
511 $string = str_replace("\246", '¦', $string);
512 $string = str_replace("\247", '§', $string);
513 $string = str_replace("\250", '¨', $string);
514 $string = str_replace("\251", '©', $string);
515 $string = str_replace("\253", '«', $string);
516 $string = str_replace("\254", '¬', $string);
517 $string = str_replace("\255", '­', $string);
518 $string = str_replace("\257", '―', $string);
519 $string = str_replace("\260", '°', $string);
520 $string = str_replace("\261", '±', $string);
521 $string = str_replace("\262", '²', $string);
522 $string = str_replace("\263", '³', $string);
524 /* Horizontal bar (parentheki pavla) */
525 $string = str_replace ("\257", '―', $string);
528 * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
529 * These are Unicode 900-902
531 $string = preg_replace("/([\264-\266])/e","'&#' . (ord('\\1')+720);",$string);
533 /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */
534 $string = str_replace("\267", '·', $string);
537 * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
538 * These are Unicode 900-902
540 $string = preg_replace("/([\270-\272])/e","'&#' . (ord('\\1')+720);",$string);
543 * 11/11 (0xBB) Right angle quotation mark is the same as in
546 $string = str_replace("\273", '»', $string);
548 /* And now the rest of the charset */
549 $string = preg_replace("/([\274-\376])/e","'&#'.(ord('\\1')+720);",$string);
555 ISOIEC 8859-9:1999 Latin Alphabet No. 5
557 function charset_decode_iso_8859_9 ($string) {
558 global $default_charset;
560 if (strtolower($default_charset) == 'iso-8859-9')
563 /* Only do the slow convert if there are 8-bit characters */
564 if (! ereg("[\200-\377]", $string))
567 // latin capital letter g with breve 208->286
568 $string = str_replace("\320", 'Ğ', $string);
569 // latin capital letter i with dot above 221->304
570 $string = str_replace("\335", 'İ', $string);
571 // latin capital letter s with cedilla 222->350
572 $string = str_replace("\336", 'Ş', $string);
573 // latin small letter g with breve 240->287
574 $string = str_replace("\360", 'ğ', $string);
575 // latin small letter dotless i 253->305
576 $string = str_replace("\375", 'ı', $string);
577 // latin small letter s with cedilla 254->351
578 $string = str_replace("\376", 'ş', $string);
580 // rest of charset is the same as ISO-8859-1
581 return (charset_decode_iso_8859_1($string));
586 ISO/IEC 8859-13:1998 Latin Alphabet No. 7 (Baltic Rim)
588 function charset_decode_iso_8859_13 ($string) {
589 global $default_charset;
591 if (strtolower($default_charset) == 'iso-8859-13')
594 /* Only do the slow convert if there are 8-bit characters */
595 if (! ereg("[\200-\377]", $string))
598 $string = str_replace ("\241", '”', $string);
599 $string = str_replace ("\245", '„', $string);
600 $string = str_replace ("\250", 'Ø', $string);
601 $string = str_replace ("\252", 'Ŗ', $string);
602 $string = str_replace ("\257", 'Æ', $string);
603 $string = str_replace ("\264", '“', $string);
604 $string = str_replace ("\270", 'ø', $string);
605 $string = str_replace ("\272", 'ŗ', $string);
606 $string = str_replace ("\277", 'æ', $string);
607 $string = str_replace ("\300", 'Ą', $string);
608 $string = str_replace ("\301", 'Į', $string);
609 $string = str_replace ("\302", 'Ā', $string);
610 $string = str_replace ("\303", 'Ć', $string);
611 $string = str_replace ("\306", 'Ę', $string);
612 $string = str_replace ("\307", 'Ē', $string);
613 $string = str_replace ("\310", 'Č', $string);
614 $string = str_replace ("\312", 'Ź', $string);
615 $string = str_replace ("\313", 'Ė', $string);
616 $string = str_replace ("\314", 'Ģ', $string);
617 $string = str_replace ("\315", 'Ķ', $string);
618 $string = str_replace ("\316", 'Ī', $string);
619 $string = str_replace ("\317", 'Ļ', $string);
620 $string = str_replace ("\320", 'Š', $string);
621 $string = str_replace ("\321", 'Ń', $string);
622 $string = str_replace ("\322", 'Ņ', $string);
623 $string = str_replace ("\324", 'Ō', $string);
624 $string = str_replace ("\330", 'Ų', $string);
625 $string = str_replace ("\331", 'Ł', $string);
626 $string = str_replace ("\332", 'Ś', $string);
627 $string = str_replace ("\333", 'Ū', $string);
628 $string = str_replace ("\335", 'Ż', $string);
629 $string = str_replace ("\336", 'Ž', $string);
630 $string = str_replace ("\340", 'ą', $string);
631 $string = str_replace ("\341", 'į', $string);
632 $string = str_replace ("\342", 'ā', $string);
633 $string = str_replace ("\343", 'ć', $string);
634 $string = str_replace ("\346", 'ę', $string);
635 $string = str_replace ("\347", 'ē', $string);
636 $string = str_replace ("\350", 'č', $string);
637 $string = str_replace ("\352", 'ź', $string);
638 $string = str_replace ("\353", 'ė', $string);
639 $string = str_replace ("\354", 'ģ', $string);
640 $string = str_replace ("\355", 'ķ', $string);
641 $string = str_replace ("\356", 'ī', $string);
642 $string = str_replace ("\357", 'ļ', $string);
643 $string = str_replace ("\360", 'š', $string);
644 $string = str_replace ("\361", 'ń', $string);
645 $string = str_replace ("\362", 'ņ', $string);
646 $string = str_replace ("\364", 'ō', $string);
647 $string = str_replace ("\370", 'ų', $string);
648 $string = str_replace ("\371", 'ł', $string);
649 $string = str_replace ("\372", 'ś', $string);
650 $string = str_replace ("\373", 'ū', $string);
651 $string = str_replace ("\375", 'ż', $string);
652 $string = str_replace ("\376", 'ž', $string);
653 $string = str_replace ("\377", '’', $string);
655 // rest of charset is the same as ISO-8859-1
656 return (charset_decode_iso_8859_1($string));
660 * iso-8859-15 is Latin 9 and has very much the same use as Latin 1
661 * but has the Euro symbol and some characters needed for French.
663 function charset_decode_iso_8859_15 ($string) {
665 $string = str_replace ("\244", '€', $string);
666 // Latin capital letter S with caron
667 $string = str_replace ("\246", 'Š', $string);
668 // Latin small letter s with caron
669 $string = str_replace ("\250", 'š', $string);
670 // Latin capital letter Z with caron
671 $string = str_replace ("\264", 'Ž', $string);
672 // Latin small letter z with caron
673 $string = str_replace ("\270", 'ž', $string);
674 // Latin capital ligature OE
675 $string = str_replace ("\274", 'Œ', $string);
676 // Latin small ligature oe
677 $string = str_replace ("\275", 'œ', $string);
678 // Latin capital letter Y with diaeresis
679 $string = str_replace ("\276", 'Ÿ', $string);
681 return (charset_decode_iso_8859_1($string));
684 /* ISO-8859-5 is Cyrillic */
685 function charset_decode_iso_8859_5 ($string) {
686 // Convert to KOI8-R, then return this decoded.
687 $string = convert_cyr_string($string, 'i', 'k');
688 return charset_decode_koi8r($string);
691 /* Remove all 8 bit characters from all other ISO-8859 character sets */
692 function charset_decode_iso_8859_default ($string) {
693 return (strtr($string, "\240\241\242\243\244\245\246\247".
694 "\250\251\252\253\254\255\256\257".
695 "\260\261\262\263\264\265\266\267".
696 "\270\271\272\273\274\275\276\277".
697 "\300\301\302\303\304\305\306\307".
698 "\310\311\312\313\314\315\316\317".
699 "\320\321\322\323\324\325\326\327".
700 "\330\331\332\333\334\335\336\337".
701 "\340\341\342\343\344\345\346\347".
702 "\350\351\352\353\354\355\356\357".
703 "\360\361\362\363\364\365\366\367".
704 "\370\371\372\373\374\375\376\377",
705 "????????????????????????????????????????".
706 "????????????????????????????????????????".
707 "????????????????????????????????????????".
713 * This is the same as ISO-646-NO and is used by some
714 * Microsoft programs when sending Norwegian characters
716 function charset_decode_ns_4551_1 ($string) {
718 * These characters are:
719 * Latin capital letter AE
720 * Latin capital letter O with stroke
721 * Latin capital letter A with ring above
722 * and the same as small letters
724 return strtr ($string, "[\\]{|}", "ÆØÅæøå");
728 * KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
731 function charset_decode_koi8r ($string) {
732 global $default_charset;
734 if ($default_charset == 'koi8-r') {
739 * Convert to Unicode HTML entities.
740 * This code is rather ineffective.
742 $string = str_replace("\200", '─', $string);
743 $string = str_replace("\201", '│', $string);
744 $string = str_replace("\202", '┌', $string);
745 $string = str_replace("\203", '┐', $string);
746 $string = str_replace("\204", '└', $string);
747 $string = str_replace("\205", '┘', $string);
748 $string = str_replace("\206", '├', $string);
749 $string = str_replace("\207", '┤', $string);
750 $string = str_replace("\210", '┬', $string);
751 $string = str_replace("\211", '┴', $string);
752 $string = str_replace("\212", '┼', $string);
753 $string = str_replace("\213", '▀', $string);
754 $string = str_replace("\214", '▄', $string);
755 $string = str_replace("\215", '█', $string);
756 $string = str_replace("\216", '▌', $string);
757 $string = str_replace("\217", '▐', $string);
758 $string = str_replace("\220", '░', $string);
759 $string = str_replace("\221", '▒', $string);
760 $string = str_replace("\222", '▓', $string);
761 $string = str_replace("\223", '⌠', $string);
762 $string = str_replace("\224", '■', $string);
763 $string = str_replace("\225", '∙', $string);
764 $string = str_replace("\226", '√', $string);
765 $string = str_replace("\227", '≈', $string);
766 $string = str_replace("\230", '≤', $string);
767 $string = str_replace("\231", '≥', $string);
768 $string = str_replace("\232", ' ', $string);
769 $string = str_replace("\233", '⌡', $string);
770 $string = str_replace("\234", '°', $string);
771 $string = str_replace("\235", '²', $string);
772 $string = str_replace("\236", '·', $string);
773 $string = str_replace("\237", '÷', $string);
774 $string = str_replace("\240", '═', $string);
775 $string = str_replace("\241", '║', $string);
776 $string = str_replace("\242", '╒', $string);
777 $string = str_replace("\243", 'ё', $string);
778 $string = str_replace("\244", '╓', $string);
779 $string = str_replace("\245", '╔', $string);
780 $string = str_replace("\246", '╕', $string);
781 $string = str_replace("\247", '╖', $string);
782 $string = str_replace("\250", '╗', $string);
783 $string = str_replace("\251", '╘', $string);
784 $string = str_replace("\252", '╙', $string);
785 $string = str_replace("\253", '╚', $string);
786 $string = str_replace("\254", '╛', $string);
787 $string = str_replace("\255", '╜', $string);
788 $string = str_replace("\256", '╝', $string);
789 $string = str_replace("\257", '╞', $string);
790 $string = str_replace("\260", '╟', $string);
791 $string = str_replace("\261", '╠', $string);
792 $string = str_replace("\262", '╡', $string);
793 $string = str_replace("\263", 'Ё', $string);
794 $string = str_replace("\264", '╢', $string);
795 $string = str_replace("\265", '╣', $string);
796 $string = str_replace("\266", '╤', $string);
797 $string = str_replace("\267", '╥', $string);
798 $string = str_replace("\270", '╦', $string);
799 $string = str_replace("\271", '╧', $string);
800 $string = str_replace("\272", '╨', $string);
801 $string = str_replace("\273", '╩', $string);
802 $string = str_replace("\274", '╪', $string);
803 $string = str_replace("\275", '╫', $string);
804 $string = str_replace("\276", '╬', $string);
805 $string = str_replace("\277", '©', $string);
806 $string = str_replace("\300", 'ю', $string);
807 $string = str_replace("\301", 'а', $string);
808 $string = str_replace("\302", 'б', $string);
809 $string = str_replace("\303", 'ц', $string);
810 $string = str_replace("\304", 'д', $string);
811 $string = str_replace("\305", 'е', $string);
812 $string = str_replace("\306", 'ф', $string);
813 $string = str_replace("\307", 'г', $string);
814 $string = str_replace("\310", 'х', $string);
815 $string = str_replace("\311", 'и', $string);
816 $string = str_replace("\312", 'й', $string);
817 $string = str_replace("\313", 'к', $string);
818 $string = str_replace("\314", 'л', $string);
819 $string = str_replace("\315", 'м', $string);
820 $string = str_replace("\316", 'н', $string);
821 $string = str_replace("\317", 'о', $string);
822 $string = str_replace("\320", 'п', $string);
823 $string = str_replace("\321", 'я', $string);
824 $string = str_replace("\322", 'р', $string);
825 $string = str_replace("\323", 'с', $string);
826 $string = str_replace("\324", 'т', $string);
827 $string = str_replace("\325", 'у', $string);
828 $string = str_replace("\326", 'ж', $string);
829 $string = str_replace("\327", 'в', $string);
830 $string = str_replace("\330", 'ь', $string);
831 $string = str_replace("\331", 'ы', $string);
832 $string = str_replace("\332", 'з', $string);
833 $string = str_replace("\333", 'ш', $string);
834 $string = str_replace("\334", 'э', $string);
835 $string = str_replace("\335", 'щ', $string);
836 $string = str_replace("\336", 'ч', $string);
837 $string = str_replace("\337", 'ъ', $string);
838 $string = str_replace("\340", 'Ю', $string);
839 $string = str_replace("\341", 'А', $string);
840 $string = str_replace("\342", 'Б', $string);
841 $string = str_replace("\343", 'Ц', $string);
842 $string = str_replace("\344", 'Д', $string);
843 $string = str_replace("\345", 'Е', $string);
844 $string = str_replace("\346", 'Ф', $string);
845 $string = str_replace("\347", 'Г', $string);
846 $string = str_replace("\350", 'Х', $string);
847 $string = str_replace("\351", 'И', $string);
848 $string = str_replace("\352", 'Й', $string);
849 $string = str_replace("\353", 'К', $string);
850 $string = str_replace("\354", 'Л', $string);
851 $string = str_replace("\355", 'М', $string);
852 $string = str_replace("\356", 'Н', $string);
853 $string = str_replace("\357", 'О', $string);
854 $string = str_replace("\360", 'П', $string);
855 $string = str_replace("\361", 'Я', $string);
856 $string = str_replace("\362", 'Р', $string);
857 $string = str_replace("\363", 'С', $string);
858 $string = str_replace("\364", 'Т', $string);
859 $string = str_replace("\365", 'У', $string);
860 $string = str_replace("\366", 'Ж', $string);
861 $string = str_replace("\367", 'В', $string);
862 $string = str_replace("\370", 'Ь', $string);
863 $string = str_replace("\371", 'Ы', $string);
864 $string = str_replace("\372", 'З', $string);
865 $string = str_replace("\373", 'Ш', $string);
866 $string = str_replace("\374", 'Э', $string);
867 $string = str_replace("\375", 'Щ', $string);
868 $string = str_replace("\376", 'Ч', $string);
869 $string = str_replace("\377", 'Ъ', $string);
877 function charset_decode_windows_1254 ($string) {
878 global $default_charset;
880 if (strtolower($default_charset) == 'windows-1254')
883 /* Only do the slow convert if there are 8-bit characters */
884 if (! ereg("[\200-\377]", $string))
887 // Euro sign 128 -> 8364
888 $string = str_replace("\200", '€', $string);
889 // Single low-9 quotation mark 130 -> 8218
890 $string = str_replace("\202", '‚', $string);
891 // latin small letter f with hook 131 -> 402
892 $string = str_replace("\203", 'ƒ', $string);
893 // Double low-9 quotation mark 132 -> 8222
894 $string = str_replace("\204", '„', $string);
895 // horizontal ellipsis 133 -> 8230
896 $string = str_replace("\205", '…', $string);
897 // dagger 134 -> 8224
898 $string = str_replace("\206", '†', $string);
899 // double dagger 135 -> 8225
900 $string = str_replace("\207", '‡', $string);
901 // modifier letter circumflex accent 136->710
902 $string = str_replace("\210", 'ˆ', $string);
903 // per mille sign 137 -> 8240
904 $string = str_replace("\211", '‰', $string);
905 // latin capital letter s with caron 138 -> 352
906 $string = str_replace("\212", 'Š', $string);
907 // single left-pointing angle quotation mark 139 -> 8249
908 $string = str_replace("\213", '‹', $string);
909 // latin capital ligature oe 140 -> 338
910 $string = str_replace("\214", 'Œ', $string);
911 // left single quotation mark 145 -> 8216
912 $string = str_replace("\221", '‘', $string);
913 // right single quotation mark 146 -> 8217
914 $string = str_replace("\222", '’', $string);
915 // left double quotation mark 147 -> 8220
916 $string = str_replace("\223", '“', $string);
917 // right double quotation mark 148 -> 8221
918 $string = str_replace("\224", '”', $string);
919 // bullet 149 -> 8226
920 $string = str_replace("\225", '•', $string);
921 // en dash 150 -> 8211
922 $string = str_replace("\226", '–', $string);
923 // em dash 151 -> 8212
924 $string = str_replace("\227", '—', $string);
925 // small tilde 152 -> 732
926 $string = str_replace("\230", '˜', $string);
927 // trade mark sign 153 -> 8482
928 $string = str_replace("\231", '™', $string);
929 // latin small letter s with caron 154 -> 353
930 $string = str_replace("\232", 'š', $string);
931 // single right-pointing angle quotation mark 155 -> 8250
932 $string = str_replace("\233", '›', $string);
933 // latin small ligature oe 156 -> 339
934 $string = str_replace("\234", 'œ', $string);
935 // latin capital letter y with diaresis 159->376
936 $string = str_replace("\237", 'Ÿ', $string);
937 // latin capital letter g with breve 208->286
938 $string = str_replace("\320", 'Ğ', $string);
939 // latin capital letter i with dot above 221->304
940 $string = str_replace("\335", 'İ', $string);
941 // latin capital letter s with cedilla 222->350
942 $string = str_replace("\336", 'Ş', $string);
943 // latin small letter g with breve 240->287
944 $string = str_replace("\360", 'ğ', $string);
945 // latin small letter dotless i 253->305
946 $string = str_replace("\375", 'ı', $string);
947 // latin small letter s with cedilla 254->351
948 $string = str_replace("\376", 'ş', $string);
950 // Rest of charset is like iso-8859-1
951 return (charset_decode_iso_8859_1($string));
957 function charset_decode_windows_1253 ($string) {
958 global $default_charset;
960 if (strtolower($default_charset) == 'windows-1253')
963 /* Only do the slow convert if there are 8-bit characters */
964 if (! ereg("[\200-\377]", $string))
967 $string = str_replace("\200", '€', $string);
968 $string = str_replace("\202", '‚', $string);
969 $string = str_replace("\203", 'ƒ', $string);
970 $string = str_replace("\204", '„', $string);
971 $string = str_replace("\205", '…', $string);
972 $string = str_replace("\206", '†', $string);
973 $string = str_replace("\207", '‡', $string);
974 $string = str_replace("\211", '‰', $string);
975 $string = str_replace("\213", '‹', $string);
976 $string = str_replace("\221", '‘', $string);
977 $string = str_replace("\222", '’', $string);
978 $string = str_replace("\223", '“', $string);
979 $string = str_replace("\224", '”', $string);
980 $string = str_replace("\225", '•', $string);
981 $string = str_replace("\226", '–', $string);
982 $string = str_replace("\227", '—', $string);
983 $string = str_replace("\231", '™', $string);
984 $string = str_replace("\233", '›', $string);
985 $string = str_replace("\241", '΅', $string);
986 $string = str_replace("\242", 'Ά', $string);
987 $string = str_replace ("\257", '―', $string);
988 $string = str_replace("\264", '΄', $string);
989 $string = str_replace("\270", 'Έ', $string);
990 $string = str_replace ("\271", 'Ή', $string);
991 $string = str_replace ("\272", 'Ί', $string);
992 $string = str_replace ("\274", 'Ό', $string);
993 // cycle for 190-254 symbols
994 $string = preg_replace("/([\274-\376])/e","'&#' . (ord('\\1')+720);",$string);
996 // Rest of charset is like iso-8859-1
997 return (charset_decode_iso_8859_1($string));
1002 windows-1257 (BaltRim)
1004 function charset_decode_windows_1257 ($string) {
1005 global $default_charset;
1007 if (strtolower($default_charset) == 'windows-1257')
1010 /* Only do the slow convert if there are 8-bit characters */
1011 if (! ereg("[\200-\377]", $string))
1014 $string = str_replace("\200", '€', $string);
1015 $string = str_replace("\202", '‚', $string);
1016 $string = str_replace("\204", '„', $string);
1017 $string = str_replace("\205", '…', $string);
1018 $string = str_replace("\206", '†', $string);
1019 $string = str_replace("\207", '‡', $string);
1020 $string = str_replace("\211", '‰', $string);
1021 $string = str_replace("\213", '‹', $string);
1022 $string = str_replace("\215", '¨', $string);
1023 $string = str_replace("\216", 'ˇ', $string);
1024 $string = str_replace("\217", '¸', $string);
1025 $string = str_replace("\221", '‘', $string);
1026 $string = str_replace("\222", '’', $string);
1027 $string = str_replace("\223", '“', $string);
1028 $string = str_replace("\224", '”', $string);
1029 $string = str_replace("\225", '•', $string);
1030 $string = str_replace("\226", '–', $string);
1031 $string = str_replace("\227", '—', $string);
1032 $string = str_replace("\231", '™', $string);
1033 $string = str_replace("\233", '›', $string);
1034 $string = str_replace("\235", '¯', $string);
1035 $string = str_replace("\236", '˛', $string);
1036 $string = str_replace ("\250", 'Ø', $string);
1037 $string = str_replace ("\252", 'Ŗ', $string);
1038 $string = str_replace ("\257", 'Æ', $string);
1039 $string = str_replace ("\270", 'ø', $string);
1040 $string = str_replace ("\272", 'ŗ', $string);
1041 $string = str_replace ("\277", 'æ', $string);
1042 $string = str_replace ("\300", 'Ą', $string);
1043 $string = str_replace ("\301", 'Į', $string);
1044 $string = str_replace ("\302", 'Ā', $string);
1045 $string = str_replace ("\303", 'Ć', $string);
1046 $string = str_replace ("\306", 'Ę', $string);
1047 $string = str_replace ("\307", 'Ē', $string);
1048 $string = str_replace ("\310", 'Č', $string);
1049 $string = str_replace ("\312", 'Ź', $string);
1050 $string = str_replace ("\313", 'Ė', $string);
1051 $string = str_replace ("\314", 'Ģ', $string);
1052 $string = str_replace ("\315", 'Ķ', $string);
1053 $string = str_replace ("\316", 'Ī', $string);
1054 $string = str_replace ("\317", 'Ļ', $string);
1055 $string = str_replace ("\320", 'Š', $string);
1056 $string = str_replace ("\321", 'Ń', $string);
1057 $string = str_replace ("\322", 'Ņ', $string);
1058 $string = str_replace ("\324", 'Ō', $string);
1059 $string = str_replace ("\330", 'Ų', $string);
1060 $string = str_replace ("\331", 'Ł', $string);
1061 $string = str_replace ("\332", 'Ŕ', $string);
1062 $string = str_replace ("\333", 'Ū', $string);
1063 $string = str_replace ("\335", 'Ż', $string);
1064 $string = str_replace ("\336", 'Ž', $string);
1065 $string = str_replace ("\340", 'ą', $string);
1066 $string = str_replace ("\341", 'į', $string);
1067 $string = str_replace ("\342", 'ā', $string);
1068 $string = str_replace ("\343", 'ć', $string);
1069 $string = str_replace ("\346", 'ę', $string);
1070 $string = str_replace ("\347", 'ē', $string);
1071 $string = str_replace ("\350", 'č', $string);
1072 $string = str_replace ("\352", 'ź', $string);
1073 $string = str_replace ("\353", 'ė', $string);
1074 $string = str_replace ("\354", 'ģ', $string);
1075 $string = str_replace ("\355", 'ķ', $string);
1076 $string = str_replace ("\356", 'ī', $string);
1077 $string = str_replace ("\357", 'ļ', $string);
1078 $string = str_replace ("\360", 'š', $string);
1079 $string = str_replace ("\361", 'ń', $string);
1080 $string = str_replace ("\362", 'ņ', $string);
1081 $string = str_replace ("\364", 'ō', $string);
1082 $string = str_replace ("\370", 'ų', $string);
1083 $string = str_replace ("\371", 'ł', $string);
1084 $string = str_replace ("\372", 'ś', $string);
1085 $string = str_replace ("\373", 'ū', $string);
1086 $string = str_replace ("\375", 'ż', $string);
1087 $string = str_replace ("\376", 'ž', $string);
1088 $string = str_replace ("\377", '˙', $string);
1090 // Rest of charset is like iso-8859-1
1091 return (charset_decode_iso_8859_1($string));
1094 /* windows-1251 is Microsoft Cyrillic encoding */
1095 function charset_decode_windows_1251 ($string) {
1096 // Convert to KOI8-R, then return this decoded.
1097 $string = convert_cyr_string($string, 'w', 'k');
1098 return charset_decode_koi8r($string);
1104 * Set up the language to be output
1105 * if $do_search is true, then scan the browser information
1106 * for a possible language that we know
1108 function set_up_language($sm_language, $do_search = false) {
1110 static $SetupAlready = 0;
1111 global $use_gettext, $languages,
1112 $squirrelmail_language, $squirrelmail_default_language,
1115 if ($SetupAlready) {
1119 $SetupAlready = TRUE;
1121 if ($do_search && ! $sm_language && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
1122 $sm_language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
1125 if (!$sm_language && isset($squirrelmail_default_language)) {
1126 $squirrelmail_language = $squirrelmail_default_language;
1127 $sm_language = $squirrelmail_default_language;
1129 $sm_notAlias = $sm_language;
1130 while (isset($languages[$sm_notAlias]['ALIAS'])) {
1131 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
1134 if ( isset($sm_language) &&
1136 $sm_language != '' &&
1137 isset($languages[$sm_notAlias]['CHARSET']) ) {
1138 bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
1139 textdomain( 'squirrelmail' );
1140 if ( !ini_get('safe_mode') &&
1141 getenv( 'LC_ALL' ) != $sm_notAlias ) {
1142 putenv( "LC_ALL=$sm_notAlias" );
1143 putenv( "LANG=$sm_notAlias" );
1144 putenv( "LANGUAGE=$sm_notAlias" );
1146 setlocale(LC_ALL
, $sm_notAlias);
1147 $squirrelmail_language = $sm_notAlias;
1148 if ($squirrelmail_language == 'ja_JP' && function_exists('mb_detect_encoding') ) {
1149 header ('Content-Type: text/html; charset=EUC-JP');
1150 if (!function_exists('mb_internal_encoding')) {
1151 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --with-mbstring).");
1153 mb_internal_encoding('EUC-JP');
1154 mb_http_output('pass');
1156 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
1161 function set_my_charset(){
1164 * There can be a $default_charset setting in the
1165 * config.php file, but the user may have a different language
1166 * selected for a user interface. This function checks the
1167 * language selected by the user and tags the outgoing messages
1168 * with the appropriate charset corresponding to the language
1169 * selection. This is "more right" (tm), than just stamping the
1170 * message blindly with the system-wide $default_charset.
1172 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
1174 $my_language = getPref($data_dir, $username, 'language');
1175 if (!$my_language) {
1176 $my_language = $squirrelmail_default_language ;
1178 while (isset($languages[$my_language]['ALIAS'])) {
1179 $my_language = $languages[$my_language]['ALIAS'];
1181 $my_charset = $languages[$my_language]['CHARSET'];
1183 $default_charset = $my_charset;
1187 /* ------------------------------ main --------------------------- */
1189 global $squirrelmail_language, $languages, $use_gettext;
1191 if (! isset($squirrelmail_language)) {
1192 $squirrelmail_language = '';
1195 /* This array specifies the available languages. */
1197 // The glibc locale is ca_ES.
1199 $languages['ca_ES']['NAME'] = 'Catalan';
1200 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
1201 $languages['ca']['ALIAS'] = 'ca_ES';
1203 $languages['cs_CZ']['NAME'] = 'Czech';
1204 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
1205 $languages['cs']['ALIAS'] = 'cs_CZ';
1207 // Danish locale is da_DK.
1209 $languages['da_DK']['NAME'] = 'Danish';
1210 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
1211 $languages['da']['ALIAS'] = 'da_DK';
1213 $languages['de_DE']['NAME'] = 'Deutsch';
1214 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
1215 $languages['de']['ALIAS'] = 'de_DE';
1217 // There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
1218 // but who cares about !US, right? Right? :)
1220 $languages['el_GR']['NAME'] = 'Greek';
1221 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
1222 $languages['el']['ALIAS'] = 'el_GR';
1224 $languages['en_US']['NAME'] = 'English';
1225 $languages['en_US']['CHARSET'] = 'iso-8859-1';
1226 $languages['en']['ALIAS'] = 'en_US';
1228 $languages['es_ES']['NAME'] = 'Spanish';
1229 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
1230 $languages['es']['ALIAS'] = 'es_ES';
1232 $languages['et_EE']['NAME'] = 'Estonian';
1233 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
1234 $languages['et']['ALIAS'] = 'et_EE';
1236 $languages['fi_FI']['NAME'] = 'Finnish';
1237 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
1238 $languages['fi']['ALIAS'] = 'fi_FI';
1240 $languages['fr_FR']['NAME'] = 'French';
1241 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
1242 $languages['fr']['ALIAS'] = 'fr_FR';
1244 $languages['hr_HR']['NAME'] = 'Croatian';
1245 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
1246 $languages['hr']['ALIAS'] = 'hr_HR';
1248 $languages['hu_HU']['NAME'] = 'Hungarian';
1249 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
1250 $languages['hu']['ALIAS'] = 'hu_HU';
1252 $languages['id_ID']['NAME'] = 'Indonesian';
1253 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
1254 $languages['id']['ALIAS'] = 'id_ID';
1256 $languages['is_IS']['NAME'] = 'Icelandic';
1257 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
1258 $languages['is']['ALIAS'] = 'is_IS';
1260 $languages['it_IT']['NAME'] = 'Italian';
1261 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
1262 $languages['it']['ALIAS'] = 'it_IT';
1264 $languages['ja_JP']['NAME'] = 'Japanese';
1265 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
1266 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
1267 $languages['ja']['ALIAS'] = 'ja_JP';
1269 $languages['ko_KR']['NAME'] = 'Korean';
1270 $languages['ko_KR']['CHARSET'] = 'euc-KR';
1271 $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
1272 $languages['ko']['ALIAS'] = 'ko_KR';
1274 $languages['nl_NL']['NAME'] = 'Dutch';
1275 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
1276 $languages['nl']['ALIAS'] = 'nl_NL';
1278 $languages['no_NO']['NAME'] = 'Norwegian (Bokmål)';
1279 $languages['no_NO']['CHARSET'] = 'iso-8859-1';
1280 $languages['no']['ALIAS'] = 'no_NO';
1281 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
1282 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
1284 $languages['pl_PL']['NAME'] = 'Polish';
1285 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
1286 $languages['pl']['ALIAS'] = 'pl_PL';
1288 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
1289 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
1290 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
1291 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
1292 $languages['pt']['ALIAS'] = 'pt_PT';
1294 $languages['ru_RU']['NAME'] = 'Russian';
1295 $languages['ru_RU']['CHARSET'] = 'koi8-r';
1296 $languages['ru']['ALIAS'] = 'ru_RU';
1298 $languages['sr_YU']['NAME'] = 'Serbian';
1299 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
1300 $languages['sr']['ALIAS'] = 'sr_YU';
1302 $languages['sv_SE']['NAME'] = 'Swedish';
1303 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
1304 $languages['sv']['ALIAS'] = 'sv_SE';
1306 $languages['tr_TR']['NAME'] = 'Turkish';
1307 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
1308 $languages['tr']['ALIAS'] = 'tr_TR';
1310 $languages['zh_TW']['NAME'] = 'Chinese Trad';
1311 $languages['zh_TW']['CHARSET'] = 'big5';
1312 $languages['tw']['ALIAS'] = 'zh_TW';
1314 $languages['zh_CN']['NAME'] = 'Chinese Simp';
1315 $languages['zh_CN']['CHARSET'] = 'gb2312';
1316 $languages['cn']['ALIAS'] = 'zh_CN';
1318 $languages['sk_SK']['NAME'] = 'Slovak';
1319 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
1320 $languages['sk']['ALIAS'] = 'sk_SK';
1322 $languages['ro_RO']['NAME'] = 'Romanian';
1323 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
1324 $languages['ro']['ALIAS'] = 'ro_RO';
1326 $languages['th_TH']['NAME'] = 'Thai';
1327 $languages['th_TH']['CHARSET'] = 'tis-620';
1328 $languages['th']['ALIAS'] = 'th_TH';
1330 $languages['lt_LT']['NAME'] = 'Lithuanian';
1331 $languages['lt_LT']['CHARSET'] = 'windows-1257';
1332 $languages['lt']['ALIAS'] = 'lt_LT';
1334 $languages['sl_SI']['NAME'] = 'Slovenian';
1335 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
1336 $languages['sl']['ALIAS'] = 'sl_SI';
1338 $languages['bg_BG']['NAME'] = 'Bulgarian';
1339 $languages['bg_BG']['CHARSET'] = 'windows-1251';
1340 $languages['bg']['ALIAS'] = 'bg_BG';
1342 $languages['uk_UA']['NAME'] = 'Ukrainian';
1343 $languages['uk_UA']['CHARSET'] = 'koi8-u';
1344 $languages['uk']['ALIAS'] = 'uk_UA';
1346 // Right to left languages
1348 $languages['ar']['NAME'] = 'Arabic';
1349 $languages['ar']['CHARSET'] = 'windows-1256';
1350 $languages['ar']['DIR'] = 'rtl';
1352 $languages['he_IL']['NAME'] = 'Hebrew';
1353 $languages['he_IL']['CHARSET'] = 'windows-1255';
1354 $languages['he_IL']['DIR'] = 'rtl';
1355 $languages['he']['ALIAS'] = 'he_IL';
1358 /* Detect whether gettext is installed. */
1360 if (function_exists('_')) {
1361 $gettext_flags +
= 1;
1363 if (function_exists('bindtextdomain')) {
1364 $gettext_flags +
= 2;
1366 if (function_exists('textdomain')) {
1367 $gettext_flags +
= 4;
1370 /* If gettext is fully loaded, cool */
1371 if ($gettext_flags == 7) {
1372 $use_gettext = true;
1374 /* If we can fake gettext, try that */
1375 elseif ($gettext_flags == 0) {
1376 $use_gettext = true;
1377 include_once(SM_PATH
. 'functions/gettext.php');
1379 /* Uh-ho. A weird install */
1380 if (! $gettext_flags & 1) {
1385 if (! $gettext_flags & 2) {
1386 function bindtextdomain() {
1390 if (! $gettext_flags & 4) {
1391 function textdomain() {
1397 function charset_decode_utf8 ($string) {
1399 Every decoded character consists of n bytes. First byte is octal
1400 300-375, other bytes - always octals 200-277.
1402 \a\b characters are decoded to html code octdec(a-300)*64 + octdec(b-200)
1403 \a\b\c characters are decoded to html code octdec(a-340)*64*64 + octdec(b-200)*64 + octdec(c-200)
1405 decoding cycle is unfinished. please test and report problems to tokul@users.sourceforge.net
1407 global $default_charset, $languages, $sm_notAlias;
1409 if (strtolower($default_charset) == 'utf-8')
1411 if (strtolower($languages[$sm_notAlias]['CHARSET']) == 'utf-8')
1414 /* Only do the slow convert if there are 8-bit characters */
1415 if (! ereg("[\200-\377]", $string))
1418 // decode three byte unicode characters
1419 $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
1420 "'&#'.((ord('\\1')-224)*4096+(ord('\\2')-128)*64+(ord('\\3')-128)).';'",
1423 // decode two byte unicode characters
1424 $string = preg_replace("/([\300-\337])([\200-\277])/e",
1425 "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
1432 * Japanese charset extra function
1435 function japanese_charset_xtra() {
1436 $ret = func_get_arg(1); /* default return value */
1437 if (function_exists('mb_detect_encoding')) {
1438 switch (func_get_arg(0)) { /* action */
1440 $detect_encoding = mb_detect_encoding($ret);
1441 if ($detect_encoding == 'JIS' ||
1442 $detect_encoding == 'EUC-JP' ||
1443 $detect_encoding == 'SJIS') {
1445 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1449 $detect_encoding = mb_detect_encoding($ret);
1450 if ($detect_encoding == 'JIS' ||
1451 $detect_encoding == 'EUC-JP' ||
1452 $detect_encoding == 'SJIS') {
1454 $ret = mb_convert_encoding($ret, 'JIS', 'AUTO');
1458 $width = func_get_arg(2);
1459 $ret = mb_strimwidth($ret, 0, $width, '...');
1461 case 'encodeheader':
1463 if (strlen($ret) > 0) {
1464 $tmpstr = mb_substr($ret, 0, 1);
1465 $prevcsize = strlen($tmpstr);
1466 for ($i = 1; $i < mb_strlen($ret); $i++
) {
1467 $tmp = mb_substr($ret, $i, 1);
1468 if (strlen($tmp) == $prevcsize) {
1471 if ($prevcsize == 1) {
1474 $result .= mb_encode_mimeheader($tmpstr);
1477 $prevcsize = strlen($tmp);
1480 if (strlen($tmpstr)) {
1481 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
1484 $result .= mb_encode_mimeheader($tmpstr);
1488 //$ret = mb_encode_mimeheader($ret);
1490 case 'decodeheader':
1491 $ret = str_replace("\t", "", $ret);
1492 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
1493 $ret = mb_decode_mimeheader($ret);
1494 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1496 case 'downloadfilename':
1497 $useragent = func_get_arg(2);
1498 if (strstr($useragent, 'Windows') !== false ||
1499 strstr($useragent, 'Mac_') !== false) {
1500 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
1502 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
1512 * Korean charset extra function
1513 * Hangul(Korean Character) Attached File Name Fix.
1515 function korean_charset_xtra() {
1517 $ret = func_get_arg(1); /* default return value */
1518 if (func_get_arg(0) == 'downloadfilename') { /* action */
1519 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
1520 for ($i=0;$i<strlen($ret);$i++
) {
1521 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
1524 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') ||
/* From Original ereg_replace in download.php */
1525 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
1526 ($ret[$i] == '.') ||
($ret[$i] == '-')) {