c817e9ffd5823878a37dc99e877962a8679b9df2
[squirrelmail.git] / functions / decode / tis_620.php
1 <?php
2 /**
3 * decode/tis620.php
4 * $Id$
5 *
6 * Copyright (c) 2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains tis620 decoding function that is needed to read
10 * tis620 encoded mails in non-tis620 locale.
11 *
12 * Original data taken from:
13 * http://www.inet.co.th/cyberclub/trin/thairef/tis620-iso10646.html
14 *
15 * Original copyright:
16 * Note: The information contained herein is provided as-is. It was
17 * complied from various references given at the end of the page.
18 * The author (trin@mozart.inet.co.th) believes all information
19 * presented here is accurate.
20 *
21 * References
22 * 1. [1]TIS 620-2533 Standard for Thai Character Codes for Computers
23 * (in Thai), [2]Thai Industrial Standards Institute
24 * 2. [3]Thai Information Technology Standards, On-line resources at the
25 * National Electronics and Computer Technology Center (NECTEC)
26 * 3. ISO/IEC 10646-1, [4]ISO/IEC JTC1/SC2
27 * 4. [5]Thai block in Unicode 2.1, [6]Unicode Consortium
28 *
29 * Links
30 * 1. http://www.nectec.or.th/it-standards/std620/std620.htm
31 * 2. http://www.tisi.go.th/
32 * 3. http://www.nectec.or.th/it-standards/
33 * 4. http://wwwold.dkuug.dk/JTC1/SC2/
34 * 5. http://charts.unicode.org/Unicode.charts/normal/U0E00.html
35 * 6. http://www.unicode.org/
36 *
37 * @package squirrelmail
38 * @subpackage decode
39 */
40
41 /**
42 * Decode tis620 encoded strings
43 * @param string $string Encoded string
44 * @return string Decoded string
45 */
46 function charset_decode_tis_620 ($string) {
47 global $default_charset;
48
49 if (strtolower($default_charset) == 'tis-620')
50 return $string;
51
52 /* Only do the slow convert if there are 8-bit characters */
53 /* there is no 0x80-0x9F letters in TIS620 */
54 if ( ! ereg("[\241-\377]", $string) )
55 return $string;
56
57 $tis620 = array(
58 "\xA0" => '&#65535;',
59 "\xA1" => '&#3585;',
60 "\xA2" => '&#3586;',
61 "\xA3" => '&#3587;',
62 "\xA4" => '&#3588;',
63 "\xA5" => '&#3589;',
64 "\xA6" => '&#3590;',
65 "\xA7" => '&#3591;',
66 "\xA8" => '&#3592;',
67 "\xA9" => '&#3593;',
68 "\xAA" => '&#3594;',
69 "\xAB" => '&#3595;',
70 "\xAC" => '&#3596;',
71 "\xAD" => '&#3597;',
72 "\xAE" => '&#3598;',
73 "\xAF" => '&#3599;',
74 "\xB0" => '&#3600;',
75 "\xB1" => '&#3601;',
76 "\xB2" => '&#3602;',
77 "\xB3" => '&#3603;',
78 "\xB4" => '&#3604;',
79 "\xB5" => '&#3605;',
80 "\xB6" => '&#3606;',
81 "\xB7" => '&#3607;',
82 "\xB8" => '&#3608;',
83 "\xB9" => '&#3609;',
84 "\xBA" => '&#3610;',
85 "\xBB" => '&#3611;',
86 "\xBC" => '&#3612;',
87 "\xBD" => '&#3613;',
88 "\xBE" => '&#3614;',
89 "\xBF" => '&#3615;',
90 "\xC0" => '&#3616;',
91 "\xC1" => '&#3617;',
92 "\xC2" => '&#3618;',
93 "\xC3" => '&#3619;',
94 "\xC4" => '&#3620;',
95 "\xC5" => '&#3621;',
96 "\xC6" => '&#3622;',
97 "\xC7" => '&#3623;',
98 "\xC8" => '&#3624;',
99 "\xC9" => '&#3625;',
100 "\xCA" => '&#3626;',
101 "\xCB" => '&#3627;',
102 "\xCC" => '&#3628;',
103 "\xCD" => '&#3629;',
104 "\xCE" => '&#3630;',
105 "\xCF" => '&#3631;',
106 "\xD0" => '&#3632;',
107 "\xD1" => '&#3633;',
108 "\xD2" => '&#3634;',
109 "\xD3" => '&#3635;',
110 "\xD4" => '&#3636;',
111 "\xD5" => '&#3637;',
112 "\xD6" => '&#3638;',
113 "\xD7" => '&#3639;',
114 "\xD8" => '&#3640;',
115 "\xD9" => '&#3641;',
116 "\xDA" => '&#3642;',
117 "\xDB" => '&#65535;',
118 "\xDC" => '&#65535;',
119 "\xDD" => '&#65535;',
120 "\xDE" => '&#65535;',
121 "\xDF" => '&#3647;',
122 "\xE0" => '&#3648;',
123 "\xE1" => '&#3649;',
124 "\xE2" => '&#3650;',
125 "\xE3" => '&#3651;',
126 "\xE4" => '&#3652;',
127 "\xE5" => '&#3653;',
128 "\xE6" => '&#3654;',
129 "\xE7" => '&#3655;',
130 "\xE8" => '&#3656;',
131 "\xE9" => '&#3657;',
132 "\xEA" => '&#3658;',
133 "\xEB" => '&#3659;',
134 "\xEC" => '&#3660;',
135 "\xED" => '&#3661;',
136 "\xEE" => '&#3662;',
137 "\xEF" => '&#3663;',
138 "\xF0" => '&#3664;',
139 "\xF1" => '&#3665;',
140 "\xF2" => '&#3666;',
141 "\xF3" => '&#3667;',
142 "\xF4" => '&#3668;',
143 "\xF5" => '&#3669;',
144 "\xF6" => '&#3670;',
145 "\xF7" => '&#3671;',
146 "\xF8" => '&#3672;',
147 "\xF9" => '&#3673;',
148 "\xFA" => '&#3674;',
149 "\xFB" => '&#3675;',
150 "\xFC" => '&#65535;',
151 "\xFD" => '&#65535;',
152 "\xFE" => '&#65535;',
153 "\xFF" => '&#65535;'
154 );
155
156 $string = str_replace(array_keys($tis620), array_values($tis620), $string);
157
158 return $string;
159 }
160
161 ?>