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