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