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