spellcheck
[squirrelmail.git] / functions / decode / cp866.php
1 <?php
2 /**
3 * decode/cp866.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 cp866 decoding function that is needed to read
9 * cp866 encoded mails in non-cp866 locale.
10 *
11 * Original data taken from:
12 * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/
13
14 Name: cp866_DOSCyrillicRussian to Unicode table
15 Unicode version: 2.0
16 Table version: 2.00
17 Table format: Format A
18 Date: 04/24/96
19 Authors: Lori Brownell <loribr@microsoft.com>
20 K.D. Chang <a-kchang@microsoft.com>
21 The entries are in cp866_DOSCyrillicRussian order
22 *
23 * @version $Id$
24 * @package squirrelmail
25 * @subpackage decode
26 */
27
28 /**
29 * Decode a cp866-encoded string
30 * @param string $string Encoded string
31 * @return string $string Decoded string
32 */
33 function charset_decode_cp866 ($string) {
34 global $default_charset;
35
36 if (strtolower($default_charset) == 'ibm866')
37 return $string;
38
39 /* Only do the slow convert if there are 8-bit characters */
40 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
41 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
42 return $string;
43
44 $cp866 = array(
45 "\x80" => '&#1040;',
46 "\x81" => '&#1041;',
47 "\x82" => '&#1042;',
48 "\x83" => '&#1043;',
49 "\x84" => '&#1044;',
50 "\x85" => '&#1045;',
51 "\x86" => '&#1046;',
52 "\x87" => '&#1047;',
53 "\x88" => '&#1048;',
54 "\x89" => '&#1049;',
55 "\x8a" => '&#1050;',
56 "\x8b" => '&#1051;',
57 "\x8c" => '&#1052;',
58 "\x8d" => '&#1053;',
59 "\x8e" => '&#1054;',
60 "\x8f" => '&#1055;',
61 "\x90" => '&#1056;',
62 "\x91" => '&#1057;',
63 "\x92" => '&#1058;',
64 "\x93" => '&#1059;',
65 "\x94" => '&#1060;',
66 "\x95" => '&#1061;',
67 "\x96" => '&#1062;',
68 "\x97" => '&#1063;',
69 "\x98" => '&#1064;',
70 "\x99" => '&#1065;',
71 "\x9a" => '&#1066;',
72 "\x9b" => '&#1067;',
73 "\x9c" => '&#1068;',
74 "\x9d" => '&#1069;',
75 "\x9e" => '&#1070;',
76 "\x9f" => '&#1071;',
77 "\xa0" => '&#1072;',
78 "\xa1" => '&#1073;',
79 "\xa2" => '&#1074;',
80 "\xa3" => '&#1075;',
81 "\xa4" => '&#1076;',
82 "\xa5" => '&#1077;',
83 "\xa6" => '&#1078;',
84 "\xa7" => '&#1079;',
85 "\xa8" => '&#1080;',
86 "\xa9" => '&#1081;',
87 "\xaa" => '&#1082;',
88 "\xab" => '&#1083;',
89 "\xac" => '&#1084;',
90 "\xad" => '&#1085;',
91 "\xae" => '&#1086;',
92 "\xaf" => '&#1087;',
93 "\xb0" => '&#9617;',
94 "\xb1" => '&#9618;',
95 "\xb2" => '&#9619;',
96 "\xb3" => '&#9474;',
97 "\xb4" => '&#9508;',
98 "\xb5" => '&#9569;',
99 "\xb6" => '&#9570;',
100 "\xb7" => '&#9558;',
101 "\xb8" => '&#9557;',
102 "\xb9" => '&#9571;',
103 "\xba" => '&#9553;',
104 "\xbb" => '&#9559;',
105 "\xbc" => '&#9565;',
106 "\xbd" => '&#9564;',
107 "\xbe" => '&#9563;',
108 "\xbf" => '&#9488;',
109 "\xc0" => '&#9492;',
110 "\xc1" => '&#9524;',
111 "\xc2" => '&#9516;',
112 "\xc3" => '&#9500;',
113 "\xc4" => '&#9472;',
114 "\xc5" => '&#9532;',
115 "\xc6" => '&#9566;',
116 "\xc7" => '&#9567;',
117 "\xc8" => '&#9562;',
118 "\xc9" => '&#9556;',
119 "\xca" => '&#9577;',
120 "\xcb" => '&#9574;',
121 "\xcc" => '&#9568;',
122 "\xcd" => '&#9552;',
123 "\xce" => '&#9580;',
124 "\xcf" => '&#9575;',
125 "\xd0" => '&#9576;',
126 "\xd1" => '&#9572;',
127 "\xd2" => '&#9573;',
128 "\xd3" => '&#9561;',
129 "\xd4" => '&#9560;',
130 "\xd5" => '&#9554;',
131 "\xd6" => '&#9555;',
132 "\xd7" => '&#9579;',
133 "\xd8" => '&#9578;',
134 "\xd9" => '&#9496;',
135 "\xda" => '&#9484;',
136 "\xdb" => '&#9608;',
137 "\xdc" => '&#9604;',
138 "\xdd" => '&#9612;',
139 "\xde" => '&#9616;',
140 "\xdf" => '&#9600;',
141 "\xe0" => '&#1088;',
142 "\xe1" => '&#1089;',
143 "\xe2" => '&#1090;',
144 "\xe3" => '&#1091;',
145 "\xe4" => '&#1092;',
146 "\xe5" => '&#1093;',
147 "\xe6" => '&#1094;',
148 "\xe7" => '&#1095;',
149 "\xe8" => '&#1096;',
150 "\xe9" => '&#1097;',
151 "\xea" => '&#1098;',
152 "\xeb" => '&#1099;',
153 "\xec" => '&#1100;',
154 "\xed" => '&#1101;',
155 "\xee" => '&#1102;',
156 "\xef" => '&#1103;',
157 "\xf0" => '&#1025;',
158 "\xf1" => '&#1105;',
159 "\xf2" => '&#1028;',
160 "\xf3" => '&#1108;',
161 "\xf4" => '&#1031;',
162 "\xf5" => '&#1111;',
163 "\xf6" => '&#1038;',
164 "\xf7" => '&#1118;',
165 "\xf8" => '&#176;',
166 "\xf9" => '&#8729;',
167 "\xfa" => '&#183;',
168 "\xfb" => '&#8730;',
169 "\xfc" => '&#8470;',
170 "\xfd" => '&#164;',
171 "\xfe" => '&#9632;',
172 "\xff" => '&#160;'
173 );
174
175 $string = str_replace(array_keys($cp866), array_values($cp866), $string);
176
177 return $string;
178 }