211d912f |
1 | <?php |
d6c32258 |
2 | /** |
211d912f |
3 | * decode/cp1251.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 cp1251 decoding function that is needed to read |
10 | * cp1251 encoded mails in non-cp1251 locale. |
11 | * |
12 | * Original data taken from: |
13 | * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT |
14 | * |
15 | * Name: cp1251 to Unicode table |
16 | * Unicode version: 2.0 |
17 | * Table version: 2.01 |
18 | * Table format: Format A |
19 | * Date: 04/15/98 |
20 | * Contact: cpxlate@microsoft.com |
d6c32258 |
21 | * @package squirrelmail |
22 | * @subpackage decode |
211d912f |
23 | */ |
24 | |
d6c32258 |
25 | /** |
26 | * Decode cp1251-encoded string |
27 | * @param string $string Encoded string |
28 | * @return string $string Decoded string |
29 | */ |
211d912f |
30 | function charset_decode_cp1251 ($string) { |
31 | global $default_charset; |
32 | |
33 | if (strtolower($default_charset) == 'windows-1251') |
34 | return $string; |
35 | |
36 | /* Only do the slow convert if there are 8-bit characters */ |
37 | /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */ |
38 | if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) ) |
39 | return $string; |
40 | |
41 | $cp1251 = array( |
42 | "\x80" => 'Ђ', |
43 | "\x81" => 'Ѓ', |
44 | "\x82" => '‚', |
45 | "\x83" => 'ѓ', |
46 | "\x84" => '„', |
47 | "\x85" => '…', |
48 | "\x86" => '†', |
49 | "\x87" => '‡', |
50 | "\x88" => '€', |
51 | "\x89" => '‰', |
52 | "\x8A" => 'Љ', |
53 | "\x8B" => '‹', |
54 | "\x8C" => 'Њ', |
55 | "\x8D" => 'Ќ', |
56 | "\x8E" => 'Ћ', |
57 | "\x8F" => 'Џ', |
58 | "\x90" => 'ђ', |
59 | "\x91" => '‘', |
60 | "\x92" => '’', |
61 | "\x93" => '“', |
62 | "\x94" => '”', |
63 | "\x95" => '•', |
64 | "\x96" => '–', |
65 | "\x97" => '—', |
66 | "\x98" => '�', |
67 | "\x99" => '™', |
68 | "\x9A" => 'љ', |
69 | "\x9B" => '›', |
70 | "\x9C" => 'њ', |
71 | "\x9D" => 'ќ', |
72 | "\x9E" => 'ћ', |
73 | "\x9F" => 'џ', |
74 | "\xA0" => ' ', |
75 | "\xA1" => 'Ў', |
76 | "\xA2" => 'ў', |
77 | "\xA3" => 'Ј', |
78 | "\xA4" => '¤', |
79 | "\xA5" => 'Ґ', |
80 | "\xA6" => '¦', |
81 | "\xA7" => '§', |
82 | "\xA8" => 'Ё', |
83 | "\xA9" => '©', |
84 | "\xAA" => 'Є', |
85 | "\xAB" => '«', |
86 | "\xAC" => '¬', |
87 | "\xAD" => '­', |
88 | "\xAE" => '®', |
89 | "\xAF" => 'Ї', |
90 | "\xB0" => '°', |
91 | "\xB1" => '±', |
92 | "\xB2" => 'І', |
93 | "\xB3" => 'і', |
94 | "\xB4" => 'ґ', |
95 | "\xB5" => 'µ', |
96 | "\xB6" => '¶', |
97 | "\xB7" => '·', |
98 | "\xB8" => 'ё', |
99 | "\xB9" => '№', |
100 | "\xBA" => 'є', |
101 | "\xBB" => '»', |
102 | "\xBC" => 'ј', |
103 | "\xBD" => 'Ѕ', |
104 | "\xBE" => 'ѕ', |
105 | "\xBF" => 'ї', |
106 | "\xC0" => 'А', |
107 | "\xC1" => 'Б', |
108 | "\xC2" => 'В', |
109 | "\xC3" => 'Г', |
110 | "\xC4" => 'Д', |
111 | "\xC5" => 'Е', |
112 | "\xC6" => 'Ж', |
113 | "\xC7" => 'З', |
114 | "\xC8" => 'И', |
115 | "\xC9" => 'Й', |
116 | "\xCA" => 'К', |
117 | "\xCB" => 'Л', |
118 | "\xCC" => 'М', |
119 | "\xCD" => 'Н', |
120 | "\xCE" => 'О', |
121 | "\xCF" => 'П', |
122 | "\xD0" => 'Р', |
123 | "\xD1" => 'С', |
124 | "\xD2" => 'Т', |
125 | "\xD3" => 'У', |
126 | "\xD4" => 'Ф', |
127 | "\xD5" => 'Х', |
128 | "\xD6" => 'Ц', |
129 | "\xD7" => 'Ч', |
130 | "\xD8" => 'Ш', |
131 | "\xD9" => 'Щ', |
132 | "\xDA" => 'Ъ', |
133 | "\xDB" => 'Ы', |
134 | "\xDC" => 'Ь', |
135 | "\xDD" => 'Э', |
136 | "\xDE" => 'Ю', |
137 | "\xDF" => 'Я', |
138 | "\xE0" => 'а', |
139 | "\xE1" => 'б', |
140 | "\xE2" => 'в', |
141 | "\xE3" => 'г', |
142 | "\xE4" => 'д', |
143 | "\xE5" => 'е', |
144 | "\xE6" => 'ж', |
145 | "\xE7" => 'з', |
146 | "\xE8" => 'и', |
147 | "\xE9" => 'й', |
148 | "\xEA" => 'к', |
149 | "\xEB" => 'л', |
150 | "\xEC" => 'м', |
151 | "\xED" => 'н', |
152 | "\xEE" => 'о', |
153 | "\xEF" => 'п', |
154 | "\xF0" => 'р', |
155 | "\xF1" => 'с', |
156 | "\xF2" => 'т', |
157 | "\xF3" => 'у', |
158 | "\xF4" => 'ф', |
159 | "\xF5" => 'х', |
160 | "\xF6" => 'ц', |
161 | "\xF7" => 'ч', |
162 | "\xF8" => 'ш', |
163 | "\xF9" => 'щ', |
164 | "\xFA" => 'ъ', |
165 | "\xFB" => 'ы', |
166 | "\xFC" => 'ь', |
167 | "\xFD" => 'э', |
168 | "\xFE" => 'ю', |
169 | "\xFF" => 'я' |
170 | ); |
171 | |
172 | $string = str_replace(array_keys($cp1251), array_values($cp1251), $string); |
173 | |
174 | return $string; |
175 | } |
176 | |
d6c32258 |
177 | ?> |