211d912f |
1 | <?php |
d6c32258 |
2 | /** |
211d912f |
3 | * decode/cp1251.php |
211d912f |
4 | * |
82d304a0 |
5 | * Copyright (c) 2003-2004 The SquirrelMail Project Team |
211d912f |
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 |
31841a9e |
20 | * |
21 | * @version $Id$ |
d6c32258 |
22 | * @package squirrelmail |
23 | * @subpackage decode |
211d912f |
24 | */ |
25 | |
d6c32258 |
26 | /** |
27 | * Decode cp1251-encoded string |
28 | * @param string $string Encoded string |
29 | * @return string $string Decoded string |
30 | */ |
211d912f |
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" => 'Ђ', |
44 | "\x81" => 'Ѓ', |
45 | "\x82" => '‚', |
46 | "\x83" => 'ѓ', |
47 | "\x84" => '„', |
48 | "\x85" => '…', |
49 | "\x86" => '†', |
50 | "\x87" => '‡', |
51 | "\x88" => '€', |
52 | "\x89" => '‰', |
53 | "\x8A" => 'Љ', |
54 | "\x8B" => '‹', |
55 | "\x8C" => 'Њ', |
56 | "\x8D" => 'Ќ', |
57 | "\x8E" => 'Ћ', |
58 | "\x8F" => 'Џ', |
59 | "\x90" => 'ђ', |
60 | "\x91" => '‘', |
61 | "\x92" => '’', |
62 | "\x93" => '“', |
63 | "\x94" => '”', |
64 | "\x95" => '•', |
65 | "\x96" => '–', |
66 | "\x97" => '—', |
67 | "\x98" => '�', |
68 | "\x99" => '™', |
69 | "\x9A" => 'љ', |
70 | "\x9B" => '›', |
71 | "\x9C" => 'њ', |
72 | "\x9D" => 'ќ', |
73 | "\x9E" => 'ћ', |
74 | "\x9F" => 'џ', |
75 | "\xA0" => ' ', |
76 | "\xA1" => 'Ў', |
77 | "\xA2" => 'ў', |
78 | "\xA3" => 'Ј', |
79 | "\xA4" => '¤', |
80 | "\xA5" => 'Ґ', |
81 | "\xA6" => '¦', |
82 | "\xA7" => '§', |
83 | "\xA8" => 'Ё', |
84 | "\xA9" => '©', |
85 | "\xAA" => 'Є', |
86 | "\xAB" => '«', |
87 | "\xAC" => '¬', |
88 | "\xAD" => '­', |
89 | "\xAE" => '®', |
90 | "\xAF" => 'Ї', |
91 | "\xB0" => '°', |
92 | "\xB1" => '±', |
93 | "\xB2" => 'І', |
94 | "\xB3" => 'і', |
95 | "\xB4" => 'ґ', |
96 | "\xB5" => 'µ', |
97 | "\xB6" => '¶', |
98 | "\xB7" => '·', |
99 | "\xB8" => 'ё', |
100 | "\xB9" => '№', |
101 | "\xBA" => 'є', |
102 | "\xBB" => '»', |
103 | "\xBC" => 'ј', |
104 | "\xBD" => 'Ѕ', |
105 | "\xBE" => 'ѕ', |
106 | "\xBF" => 'ї', |
107 | "\xC0" => 'А', |
108 | "\xC1" => 'Б', |
109 | "\xC2" => 'В', |
110 | "\xC3" => 'Г', |
111 | "\xC4" => 'Д', |
112 | "\xC5" => 'Е', |
113 | "\xC6" => 'Ж', |
114 | "\xC7" => 'З', |
115 | "\xC8" => 'И', |
116 | "\xC9" => 'Й', |
117 | "\xCA" => 'К', |
118 | "\xCB" => 'Л', |
119 | "\xCC" => 'М', |
120 | "\xCD" => 'Н', |
121 | "\xCE" => 'О', |
122 | "\xCF" => 'П', |
123 | "\xD0" => 'Р', |
124 | "\xD1" => 'С', |
125 | "\xD2" => 'Т', |
126 | "\xD3" => 'У', |
127 | "\xD4" => 'Ф', |
128 | "\xD5" => 'Х', |
129 | "\xD6" => 'Ц', |
130 | "\xD7" => 'Ч', |
131 | "\xD8" => 'Ш', |
132 | "\xD9" => 'Щ', |
133 | "\xDA" => 'Ъ', |
134 | "\xDB" => 'Ы', |
135 | "\xDC" => 'Ь', |
136 | "\xDD" => 'Э', |
137 | "\xDE" => 'Ю', |
138 | "\xDF" => 'Я', |
139 | "\xE0" => 'а', |
140 | "\xE1" => 'б', |
141 | "\xE2" => 'в', |
142 | "\xE3" => 'г', |
143 | "\xE4" => 'д', |
144 | "\xE5" => 'е', |
145 | "\xE6" => 'ж', |
146 | "\xE7" => 'з', |
147 | "\xE8" => 'и', |
148 | "\xE9" => 'й', |
149 | "\xEA" => 'к', |
150 | "\xEB" => 'л', |
151 | "\xEC" => 'м', |
152 | "\xED" => 'н', |
153 | "\xEE" => 'о', |
154 | "\xEF" => 'п', |
155 | "\xF0" => 'р', |
156 | "\xF1" => 'с', |
157 | "\xF2" => 'т', |
158 | "\xF3" => 'у', |
159 | "\xF4" => 'ф', |
160 | "\xF5" => 'х', |
161 | "\xF6" => 'ц', |
162 | "\xF7" => 'ч', |
163 | "\xF8" => 'ш', |
164 | "\xF9" => 'щ', |
165 | "\xFA" => 'ъ', |
166 | "\xFB" => 'ы', |
167 | "\xFC" => 'ь', |
168 | "\xFD" => 'э', |
169 | "\xFE" => 'ю', |
170 | "\xFF" => 'я' |
171 | ); |
172 | |
173 | $string = str_replace(array_keys($cp1251), array_values($cp1251), $string); |
174 | |
175 | return $string; |
176 | } |
177 | |
d6c32258 |
178 | ?> |