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