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