adding tis-620 support
[squirrelmail.git] / functions / encode / tis_620.php
1 <?php
2 /**
3 * tis-620 encoding functions
4 *
5 * takes a string of unicode entities and converts it to a tis-620 encoded string
6 * Unsupported characters are replaced with ?.
7 *
8 * @version $Id$
9 * @copyright Copyright &copy; SquirrelMail Development Team, 2004
10 * @package squirrelmail
11 * @subpackage encode
12 */
13
14 /**
15 * Converts string to tis-620
16 * @param string $string text with numeric unicode entities
17 * @return string tis-620 encoded text
18 */
19 function charset_encode_tis_620 ($string) {
20 // don't run encoding function, if there is no encoded characters
21 if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
22
23 $string=preg_replace("/&#([0-9]+);/e","unicodetotis620('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetotis620(hexdec('\\1'))",$string);
25
26 return $string;
27 }
28
29 /**
30 * Return tis-620 symbol when unicode character number is provided
31 *
32 * This function is used internally by charset_encode_tis_620
33 * function. It might be unavailable to other squirrelmail functions.
34 * Don't use it or make sure, that functions/encode/tis_620.php is
35 * included.
36 *
37 * @param int $var decimal unicode value
38 * @return string tis-620 character
39 */
40 function unicodetotis620($var) {
41
42 $tis620chars=array('3585' => "\xA1",
43 '3586' => "\xA2",
44 '3587' => "\xA3",
45 '3588' => "\xA4",
46 '3589' => "\xA5",
47 '3590' => "\xA6",
48 '3591' => "\xA7",
49 '3592' => "\xA8",
50 '3593' => "\xA9",
51 '3594' => "\xAA",
52 '3595' => "\xAB",
53 '3596' => "\xAC",
54 '3597' => "\xAD",
55 '3598' => "\xAE",
56 '3599' => "\xAF",
57 '3600' => "\xB0",
58 '3601' => "\xB1",
59 '3602' => "\xB2",
60 '3603' => "\xB3",
61 '3604' => "\xB4",
62 '3605' => "\xB5",
63 '3606' => "\xB6",
64 '3607' => "\xB7",
65 '3608' => "\xB8",
66 '3609' => "\xB9",
67 '3610' => "\xBA",
68 '3611' => "\xBB",
69 '3612' => "\xBC",
70 '3613' => "\xBD",
71 '3614' => "\xBE",
72 '3615' => "\xBF",
73 '3616' => "\xC0",
74 '3617' => "\xC1",
75 '3618' => "\xC2",
76 '3619' => "\xC3",
77 '3620' => "\xC4",
78 '3621' => "\xC5",
79 '3622' => "\xC6",
80 '3623' => "\xC7",
81 '3624' => "\xC8",
82 '3625' => "\xC9",
83 '3626' => "\xCA",
84 '3627' => "\xCB",
85 '3628' => "\xCC",
86 '3629' => "\xCD",
87 '3630' => "\xCE",
88 '3631' => "\xCF",
89 '3632' => "\xD0",
90 '3633' => "\xD1",
91 '3634' => "\xD2",
92 '3635' => "\xD3",
93 '3636' => "\xD4",
94 '3637' => "\xD5",
95 '3638' => "\xD6",
96 '3639' => "\xD7",
97 '3640' => "\xD8",
98 '3641' => "\xD9",
99 '3642' => "\xDA",
100 '3647' => "\xDF",
101 '3648' => "\xE0",
102 '3649' => "\xE1",
103 '3650' => "\xE2",
104 '3651' => "\xE3",
105 '3652' => "\xE4",
106 '3653' => "\xE5",
107 '3654' => "\xE6",
108 '3655' => "\xE7",
109 '3656' => "\xE8",
110 '3657' => "\xE9",
111 '3658' => "\xEA",
112 '3659' => "\xEB",
113 '3660' => "\xEC",
114 '3661' => "\xED",
115 '3662' => "\xEE",
116 '3663' => "\xEF",
117 '3664' => "\xF0",
118 '3665' => "\xF1",
119 '3666' => "\xF2",
120 '3667' => "\xF3",
121 '3668' => "\xF4",
122 '3669' => "\xF5",
123 '3670' => "\xF6",
124 '3671' => "\xF7",
125 '3672' => "\xF8",
126 '3673' => "\xF9",
127 '3674' => "\xFA",
128 '3675' => "\xFB");
129
130 if (array_key_exists($var,$tis620chars)) {
131 $ret=$tis620chars[$var];
132 } else {
133 $ret='?';
134 }
135 return $ret;
136 }
137 ?>