c7ddcde307633539335a7a96c766aa5eed68eb8b
[squirrelmail.git] / functions / decode / cp1251.php
1 <?php
2 /**
3 * decode/cp1251.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 cp1251 decoding function that is needed to read
9 * cp1251 encoded mails in non-cp1251 locale.
10 *
11 * Original data taken from:
12 * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT
13 *
14 * Name: cp1251 to Unicode table
15 * Unicode version: 2.0
16 * Table version: 2.01
17 * Table format: Format A
18 * Date: 04/15/98
19 * Contact: cpxlate@microsoft.com
20 *
21 * @version $Id$
22 * @package squirrelmail
23 * @subpackage decode
24 */
25
26 /**
27 * Decode cp1251-encoded string
28 * @param string $string Encoded string
29 * @return string $string Decoded string
30 */
31 function charset_decode_cp1251 ($string) {
32 global $default_charset;
33
34 if (strtolower($default_charset) == 'windows-1251')
35 return $string;
36
37 /* Only do the slow convert if there are 8-bit characters */
38 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
39 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
40 return $string;
41
42 $cp1251 = array(
43 "\x80" => '&#1026;',
44 "\x81" => '&#1027;',
45 "\x82" => '&#8218;',
46 "\x83" => '&#1107;',
47 "\x84" => '&#8222;',
48 "\x85" => '&#8230;',
49 "\x86" => '&#8224;',
50 "\x87" => '&#8225;',
51 "\x88" => '&#8364;',
52 "\x89" => '&#8240;',
53 "\x8A" => '&#1033;',
54 "\x8B" => '&#8249;',
55 "\x8C" => '&#1034;',
56 "\x8D" => '&#1036;',
57 "\x8E" => '&#1035;',
58 "\x8F" => '&#1039;',
59 "\x90" => '&#1106;',
60 "\x91" => '&#8216;',
61 "\x92" => '&#8217;',
62 "\x93" => '&#8220;',
63 "\x94" => '&#8221;',
64 "\x95" => '&#8226;',
65 "\x96" => '&#8211;',
66 "\x97" => '&#8212;',
67 "\x98" => '&#65533;',
68 "\x99" => '&#8482;',
69 "\x9A" => '&#1113;',
70 "\x9B" => '&#8250;',
71 "\x9C" => '&#1114;',
72 "\x9D" => '&#1116;',
73 "\x9E" => '&#1115;',
74 "\x9F" => '&#1119;',
75 "\xA0" => '&#160;',
76 "\xA1" => '&#1038;',
77 "\xA2" => '&#1118;',
78 "\xA3" => '&#1032;',
79 "\xA4" => '&#164;',
80 "\xA5" => '&#1168;',
81 "\xA6" => '&#166;',
82 "\xA7" => '&#167;',
83 "\xA8" => '&#1025;',
84 "\xA9" => '&#169;',
85 "\xAA" => '&#1028;',
86 "\xAB" => '&#171;',
87 "\xAC" => '&#172;',
88 "\xAD" => '&#173;',
89 "\xAE" => '&#174;',
90 "\xAF" => '&#1031;',
91 "\xB0" => '&#176;',
92 "\xB1" => '&#177;',
93 "\xB2" => '&#1030;',
94 "\xB3" => '&#1110;',
95 "\xB4" => '&#1169;',
96 "\xB5" => '&#181;',
97 "\xB6" => '&#182;',
98 "\xB7" => '&#183;',
99 "\xB8" => '&#1105;',
100 "\xB9" => '&#8470;',
101 "\xBA" => '&#1108;',
102 "\xBB" => '&#187;',
103 "\xBC" => '&#1112;',
104 "\xBD" => '&#1029;',
105 "\xBE" => '&#1109;',
106 "\xBF" => '&#1111;',
107 "\xC0" => '&#1040;',
108 "\xC1" => '&#1041;',
109 "\xC2" => '&#1042;',
110 "\xC3" => '&#1043;',
111 "\xC4" => '&#1044;',
112 "\xC5" => '&#1045;',
113 "\xC6" => '&#1046;',
114 "\xC7" => '&#1047;',
115 "\xC8" => '&#1048;',
116 "\xC9" => '&#1049;',
117 "\xCA" => '&#1050;',
118 "\xCB" => '&#1051;',
119 "\xCC" => '&#1052;',
120 "\xCD" => '&#1053;',
121 "\xCE" => '&#1054;',
122 "\xCF" => '&#1055;',
123 "\xD0" => '&#1056;',
124 "\xD1" => '&#1057;',
125 "\xD2" => '&#1058;',
126 "\xD3" => '&#1059;',
127 "\xD4" => '&#1060;',
128 "\xD5" => '&#1061;',
129 "\xD6" => '&#1062;',
130 "\xD7" => '&#1063;',
131 "\xD8" => '&#1064;',
132 "\xD9" => '&#1065;',
133 "\xDA" => '&#1066;',
134 "\xDB" => '&#1067;',
135 "\xDC" => '&#1068;',
136 "\xDD" => '&#1069;',
137 "\xDE" => '&#1070;',
138 "\xDF" => '&#1071;',
139 "\xE0" => '&#1072;',
140 "\xE1" => '&#1073;',
141 "\xE2" => '&#1074;',
142 "\xE3" => '&#1075;',
143 "\xE4" => '&#1076;',
144 "\xE5" => '&#1077;',
145 "\xE6" => '&#1078;',
146 "\xE7" => '&#1079;',
147 "\xE8" => '&#1080;',
148 "\xE9" => '&#1081;',
149 "\xEA" => '&#1082;',
150 "\xEB" => '&#1083;',
151 "\xEC" => '&#1084;',
152 "\xED" => '&#1085;',
153 "\xEE" => '&#1086;',
154 "\xEF" => '&#1087;',
155 "\xF0" => '&#1088;',
156 "\xF1" => '&#1089;',
157 "\xF2" => '&#1090;',
158 "\xF3" => '&#1091;',
159 "\xF4" => '&#1092;',
160 "\xF5" => '&#1093;',
161 "\xF6" => '&#1094;',
162 "\xF7" => '&#1095;',
163 "\xF8" => '&#1096;',
164 "\xF9" => '&#1097;',
165 "\xFA" => '&#1098;',
166 "\xFB" => '&#1099;',
167 "\xFC" => '&#1100;',
168 "\xFD" => '&#1101;',
169 "\xFE" => '&#1102;',
170 "\xFF" => '&#1103;'
171 );
172
173 $string = str_replace(array_keys($cp1251), array_values($cp1251), $string);
174
175 return $string;
176 }
177
178 ?>