Makes managing decoding easier. Mac decoding moved to separate cvs module
[squirrelmail.git] / functions / decode / koi8_r.php
1 <?php
2 /**
3 * decode/koi8-r.php
4 * $Id$
5 *
6 * Copyright (c) 2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains koi8-r decoding function that is needed to read
10 * koi8-r encoded mails in non-koi8-r locale.
11 *
12 * Original data taken from:
13 * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT
14 *
15 * Name: KOI8-R (RFC1489) to Unicode
16 * Unicode version: 3.0
17 * Table version: 1.0
18 * Table format: Format A
19 * Date: 18 August 1999
20 * Authors: Helmut Richter <richter@lrz.de>
21 *
22 * Copyright (c) 1991-1999 Unicode, Inc. All Rights reserved.
23 *
24 * This file is provided as-is by Unicode, Inc. (The Unicode Consortium).
25 * No claims are made as to fitness for any particular purpose. No
26 * warranties of any kind are expressed or implied. The recipient
27 * agrees to determine applicability of information provided. If this
28 * file has been provided on optical media by Unicode, Inc., the sole
29 * remedy for any claim will be exchange of defective media within 90
30 * days of receipt.
31 *
32 * Unicode, Inc. hereby grants the right to freely use the information
33 * supplied in this file in the creation of products supporting the
34 * Unicode Standard, and to make copies of this file in any form for
35 * internal or external distribution as long as this notice remains
36 * attached.
37 *
38 * @package squirrelmail
39 * @subpackage decode
40 */
41
42 /**
43 * Decode koi8r strings
44 * @param string $string Encoded string
45 * @return string Decoded string
46 */
47 function charset_decode_koi8_r ($string) {
48 global $default_charset;
49
50 if (strtolower($default_charset) == 'koi8-r')
51 return $string;
52
53 /* Only do the slow convert if there are 8-bit characters */
54 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
55 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
56 return $string;
57
58 $koi8r = array(
59 "\x80" => '&#9472;',
60 "\x81" => '&#9474;',
61 "\x82" => '&#9484;',
62 "\x83" => '&#9488;',
63 "\x84" => '&#9492;',
64 "\x85" => '&#9496;',
65 "\x86" => '&#9500;',
66 "\x87" => '&#9508;',
67 "\x88" => '&#9516;',
68 "\x89" => '&#9524;',
69 "\x8A" => '&#9532;',
70 "\x8B" => '&#9600;',
71 "\x8C" => '&#9604;',
72 "\x8D" => '&#9608;',
73 "\x8E" => '&#9612;',
74 "\x8F" => '&#9616;',
75 "\x90" => '&#9617;',
76 "\x91" => '&#9618;',
77 "\x92" => '&#9619;',
78 "\x93" => '&#8992;',
79 "\x94" => '&#9632;',
80 "\x95" => '&#8729;',
81 "\x96" => '&#8730;',
82 "\x97" => '&#8776;',
83 "\x98" => '&#8804;',
84 "\x99" => '&#8805;',
85 "\x9A" => '&#160;',
86 "\x9B" => '&#8993;',
87 "\x9C" => '&#176;',
88 "\x9D" => '&#178;',
89 "\x9E" => '&#183;',
90 "\x9F" => '&#247;',
91 "\xA0" => '&#9552;',
92 "\xA1" => '&#9553;',
93 "\xA2" => '&#9554;',
94 "\xA3" => '&#1105;',
95 "\xA4" => '&#9555;',
96 "\xA5" => '&#9556;',
97 "\xA6" => '&#9557;',
98 "\xA7" => '&#9558;',
99 "\xA8" => '&#9559;',
100 "\xA9" => '&#9560;',
101 "\xAA" => '&#9561;',
102 "\xAB" => '&#9562;',
103 "\xAC" => '&#9563;',
104 "\xAD" => '&#9564;',
105 "\xAE" => '&#9565;',
106 "\xAF" => '&#9566;',
107 "\xB0" => '&#9567;',
108 "\xB1" => '&#9568;',
109 "\xB2" => '&#9569;',
110 "\xB3" => '&#1025;',
111 "\xB4" => '&#9570;',
112 "\xB5" => '&#9571;',
113 "\xB6" => '&#9572;',
114 "\xB7" => '&#9573;',
115 "\xB8" => '&#9574;',
116 "\xB9" => '&#9575;',
117 "\xBA" => '&#9576;',
118 "\xBB" => '&#9577;',
119 "\xBC" => '&#9578;',
120 "\xBD" => '&#9579;',
121 "\xBE" => '&#9580;',
122 "\xBF" => '&#169;',
123 "\xC0" => '&#1102;',
124 "\xC1" => '&#1072;',
125 "\xC2" => '&#1073;',
126 "\xC3" => '&#1094;',
127 "\xC4" => '&#1076;',
128 "\xC5" => '&#1077;',
129 "\xC6" => '&#1092;',
130 "\xC7" => '&#1075;',
131 "\xC8" => '&#1093;',
132 "\xC9" => '&#1080;',
133 "\xCA" => '&#1081;',
134 "\xCB" => '&#1082;',
135 "\xCC" => '&#1083;',
136 "\xCD" => '&#1084;',
137 "\xCE" => '&#1085;',
138 "\xCF" => '&#1086;',
139 "\xD0" => '&#1087;',
140 "\xD1" => '&#1103;',
141 "\xD2" => '&#1088;',
142 "\xD3" => '&#1089;',
143 "\xD4" => '&#1090;',
144 "\xD5" => '&#1091;',
145 "\xD6" => '&#1078;',
146 "\xD7" => '&#1074;',
147 "\xD8" => '&#1100;',
148 "\xD9" => '&#1099;',
149 "\xDA" => '&#1079;',
150 "\xDB" => '&#1096;',
151 "\xDC" => '&#1101;',
152 "\xDD" => '&#1097;',
153 "\xDE" => '&#1095;',
154 "\xDF" => '&#1098;',
155 "\xE0" => '&#1070;',
156 "\xE1" => '&#1040;',
157 "\xE2" => '&#1041;',
158 "\xE3" => '&#1062;',
159 "\xE4" => '&#1044;',
160 "\xE5" => '&#1045;',
161 "\xE6" => '&#1060;',
162 "\xE7" => '&#1043;',
163 "\xE8" => '&#1061;',
164 "\xE9" => '&#1048;',
165 "\xEA" => '&#1049;',
166 "\xEB" => '&#1050;',
167 "\xEC" => '&#1051;',
168 "\xED" => '&#1052;',
169 "\xEE" => '&#1053;',
170 "\xEF" => '&#1054;',
171 "\xF0" => '&#1055;',
172 "\xF1" => '&#1071;',
173 "\xF2" => '&#1056;',
174 "\xF3" => '&#1057;',
175 "\xF4" => '&#1058;',
176 "\xF5" => '&#1059;',
177 "\xF6" => '&#1046;',
178 "\xF7" => '&#1042;',
179 "\xF8" => '&#1068;',
180 "\xF9" => '&#1067;',
181 "\xFA" => '&#1047;',
182 "\xFB" => '&#1064;',
183 "\xFC" => '&#1069;',
184 "\xFD" => '&#1065;',
185 "\xFE" => '&#1063;',
186 "\xFF" => '&#1066;'
187 );
188
189 $string = str_replace(array_keys($koi8r), array_values($koi8r), $string);
190
191 return $string;
192 }
193
194 ?>