Increment year in copyright notice.
[squirrelmail.git] / functions / encode / koi8_u.php
CommitLineData
9911dc64 1<?php
2/**
3 * koi8-u encoding functions
4 *
5 * takes a string of unicode entities and converts it to a koi8-u encoded string
6 * Unsupported characters are replaced with ?.
7 *
8 * @version $Id$
6c84ba1e 9 * @copyright Copyright &copy; 2004-2005 The SquirrelMail Project Team
9911dc64 10 * @package squirrelmail
11 * @subpackage encode
12 */
13
14/**
15 * Converts string to koi8-u
16 * @param string $string text with numeric unicode entities
17 * @return string koi8-u encoded text
18 */
19function charset_encode_koi8_u ($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","unicodetokoi8u('\\1')",$string);
24 // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetokoi8u(hexdec('\\1'))",$string);
91e0dccc 25
9911dc64 26 return $string;
27}
28
29/**
30 * Return koi8-u symbol when unicode character number is provided
91e0dccc 31 *
32 * This function is used internally by charset_encode_koi8_u
9911dc64 33 * function. It might be unavailable to other squirrelmail functions.
91e0dccc 34 * Don't use it or make sure, that functions/encode/koi8_u.php is
35 * included.
9911dc64 36 *
37 * @param int $var decimal unicode value
38 * @return string koi8-u character
39 */
40function unicodetokoi8u($var) {
41
42 $koi8uchars=array('160' => "\x9A",
43 '169' => "\xBF",
44 '176' => "\x9C",
45 '178' => "\x9D",
46 '183' => "\x9E",
47 '247' => "\x9F",
48 '1025' => "\xB3",
49 '1028' => "\xB4",
50 '1030' => "\xB6",
51 '1031' => "\xB7",
52 '1040' => "\xE1",
53 '1041' => "\xE2",
54 '1042' => "\xF7",
55 '1043' => "\xE7",
56 '1044' => "\xE4",
57 '1045' => "\xE5",
58 '1046' => "\xF6",
59 '1047' => "\xFA",
60 '1048' => "\xE9",
61 '1049' => "\xEA",
62 '1050' => "\xEB",
63 '1051' => "\xEC",
64 '1052' => "\xED",
65 '1053' => "\xEE",
66 '1054' => "\xEF",
67 '1055' => "\xF0",
68 '1056' => "\xF2",
69 '1057' => "\xF3",
70 '1058' => "\xF4",
71 '1059' => "\xF5",
72 '1060' => "\xE6",
73 '1061' => "\xE8",
74 '1062' => "\xE3",
75 '1063' => "\xFE",
76 '1064' => "\xFB",
77 '1065' => "\xFD",
78 '1066' => "\xFF",
79 '1067' => "\xF9",
80 '1068' => "\xF8",
81 '1069' => "\xFC",
82 '1070' => "\xE0",
83 '1071' => "\xF1",
84 '1072' => "\xC1",
85 '1073' => "\xC2",
86 '1074' => "\xD7",
87 '1075' => "\xC7",
88 '1076' => "\xC4",
89 '1077' => "\xC5",
90 '1078' => "\xD6",
91 '1079' => "\xDA",
92 '1080' => "\xC9",
93 '1081' => "\xCA",
94 '1082' => "\xCB",
95 '1083' => "\xCC",
96 '1084' => "\xCD",
97 '1085' => "\xCE",
98 '1086' => "\xCF",
99 '1087' => "\xD0",
100 '1088' => "\xD2",
101 '1089' => "\xD3",
102 '1090' => "\xD4",
103 '1091' => "\xD5",
104 '1092' => "\xC6",
105 '1093' => "\xC8",
106 '1094' => "\xC3",
107 '1095' => "\xDE",
108 '1096' => "\xDB",
109 '1097' => "\xDD",
110 '1098' => "\xDF",
111 '1099' => "\xD9",
112 '1100' => "\xD8",
113 '1101' => "\xDC",
114 '1102' => "\xC0",
115 '1103' => "\xD1",
116 '1105' => "\xA3",
117 '1108' => "\xA4",
118 '1110' => "\xA6",
119 '1111' => "\xA7",
120 '1168' => "\xBD",
121 '1169' => "\xAD",
122 '8729' => "\x95",
123 '8730' => "\x96",
124 '8776' => "\x97",
125 '8804' => "\x98",
126 '8805' => "\x99",
127 '8992' => "\x93",
128 '8993' => "\x9B",
129 '9472' => "\x80",
130 '9474' => "\x81",
131 '9484' => "\x82",
132 '9488' => "\x83",
133 '9492' => "\x84",
134 '9496' => "\x85",
135 '9500' => "\x86",
136 '9508' => "\x87",
137 '9516' => "\x88",
138 '9524' => "\x89",
139 '9532' => "\x8A",
140 '9552' => "\xA0",
141 '9553' => "\xA1",
142 '9554' => "\xA2",
143 '9556' => "\xA5",
144 '9559' => "\xA8",
145 '9560' => "\xA9",
146 '9561' => "\xAA",
147 '9562' => "\xAB",
148 '9563' => "\xAC",
149 '9565' => "\xAE",
150 '9566' => "\xAF",
151 '9567' => "\xB0",
152 '9568' => "\xB1",
153 '9569' => "\xB2",
154 '9571' => "\xB5",
155 '9574' => "\xB8",
156 '9575' => "\xB9",
157 '9576' => "\xBA",
158 '9577' => "\xBB",
159 '9578' => "\xBC",
160 '9580' => "\xBE",
161 '9600' => "\x8B",
162 '9604' => "\x8C",
163 '9608' => "\x8D",
164 '9612' => "\x8E",
165 '9616' => "\x8F",
166 '9617' => "\x90",
167 '9618' => "\x91",
168 '9619' => "\x92",
169 '9632' => "\x94");
170
171 if (array_key_exists($var,$koi8uchars)) {
172 $ret=$koi8uchars[$var];
173 } else {
174 $ret='?';
175 }
176 return $ret;
177}
178?>