We're living in 2004 now... perl is your friend for these kinds of things :)
[squirrelmail.git] / functions / decode / cp1251.php
CommitLineData
211d912f 1<?php
d6c32258 2/**
211d912f 3 * decode/cp1251.php
4 * $Id$
5 *
82d304a0 6 * Copyright (c) 2003-2004 The SquirrelMail Project Team
211d912f 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 30function 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" => '&#1026;',
43 "\x81" => '&#1027;',
44 "\x82" => '&#8218;',
45 "\x83" => '&#1107;',
46 "\x84" => '&#8222;',
47 "\x85" => '&#8230;',
48 "\x86" => '&#8224;',
49 "\x87" => '&#8225;',
50 "\x88" => '&#8364;',
51 "\x89" => '&#8240;',
52 "\x8A" => '&#1033;',
53 "\x8B" => '&#8249;',
54 "\x8C" => '&#1034;',
55 "\x8D" => '&#1036;',
56 "\x8E" => '&#1035;',
57 "\x8F" => '&#1039;',
58 "\x90" => '&#1106;',
59 "\x91" => '&#8216;',
60 "\x92" => '&#8217;',
61 "\x93" => '&#8220;',
62 "\x94" => '&#8221;',
63 "\x95" => '&#8226;',
64 "\x96" => '&#8211;',
65 "\x97" => '&#8212;',
66 "\x98" => '&#65533;',
67 "\x99" => '&#8482;',
68 "\x9A" => '&#1113;',
69 "\x9B" => '&#8250;',
70 "\x9C" => '&#1114;',
71 "\x9D" => '&#1116;',
72 "\x9E" => '&#1115;',
73 "\x9F" => '&#1119;',
74 "\xA0" => '&#160;',
75 "\xA1" => '&#1038;',
76 "\xA2" => '&#1118;',
77 "\xA3" => '&#1032;',
78 "\xA4" => '&#164;',
79 "\xA5" => '&#1168;',
80 "\xA6" => '&#166;',
81 "\xA7" => '&#167;',
82 "\xA8" => '&#1025;',
83 "\xA9" => '&#169;',
84 "\xAA" => '&#1028;',
85 "\xAB" => '&#171;',
86 "\xAC" => '&#172;',
87 "\xAD" => '&#173;',
88 "\xAE" => '&#174;',
89 "\xAF" => '&#1031;',
90 "\xB0" => '&#176;',
91 "\xB1" => '&#177;',
92 "\xB2" => '&#1030;',
93 "\xB3" => '&#1110;',
94 "\xB4" => '&#1169;',
95 "\xB5" => '&#181;',
96 "\xB6" => '&#182;',
97 "\xB7" => '&#183;',
98 "\xB8" => '&#1105;',
99 "\xB9" => '&#8470;',
100 "\xBA" => '&#1108;',
101 "\xBB" => '&#187;',
102 "\xBC" => '&#1112;',
103 "\xBD" => '&#1029;',
104 "\xBE" => '&#1109;',
105 "\xBF" => '&#1111;',
106 "\xC0" => '&#1040;',
107 "\xC1" => '&#1041;',
108 "\xC2" => '&#1042;',
109 "\xC3" => '&#1043;',
110 "\xC4" => '&#1044;',
111 "\xC5" => '&#1045;',
112 "\xC6" => '&#1046;',
113 "\xC7" => '&#1047;',
114 "\xC8" => '&#1048;',
115 "\xC9" => '&#1049;',
116 "\xCA" => '&#1050;',
117 "\xCB" => '&#1051;',
118 "\xCC" => '&#1052;',
119 "\xCD" => '&#1053;',
120 "\xCE" => '&#1054;',
121 "\xCF" => '&#1055;',
122 "\xD0" => '&#1056;',
123 "\xD1" => '&#1057;',
124 "\xD2" => '&#1058;',
125 "\xD3" => '&#1059;',
126 "\xD4" => '&#1060;',
127 "\xD5" => '&#1061;',
128 "\xD6" => '&#1062;',
129 "\xD7" => '&#1063;',
130 "\xD8" => '&#1064;',
131 "\xD9" => '&#1065;',
132 "\xDA" => '&#1066;',
133 "\xDB" => '&#1067;',
134 "\xDC" => '&#1068;',
135 "\xDD" => '&#1069;',
136 "\xDE" => '&#1070;',
137 "\xDF" => '&#1071;',
138 "\xE0" => '&#1072;',
139 "\xE1" => '&#1073;',
140 "\xE2" => '&#1074;',
141 "\xE3" => '&#1075;',
142 "\xE4" => '&#1076;',
143 "\xE5" => '&#1077;',
144 "\xE6" => '&#1078;',
145 "\xE7" => '&#1079;',
146 "\xE8" => '&#1080;',
147 "\xE9" => '&#1081;',
148 "\xEA" => '&#1082;',
149 "\xEB" => '&#1083;',
150 "\xEC" => '&#1084;',
151 "\xED" => '&#1085;',
152 "\xEE" => '&#1086;',
153 "\xEF" => '&#1087;',
154 "\xF0" => '&#1088;',
155 "\xF1" => '&#1089;',
156 "\xF2" => '&#1090;',
157 "\xF3" => '&#1091;',
158 "\xF4" => '&#1092;',
159 "\xF5" => '&#1093;',
160 "\xF6" => '&#1094;',
161 "\xF7" => '&#1095;',
162 "\xF8" => '&#1096;',
163 "\xF9" => '&#1097;',
164 "\xFA" => '&#1098;',
165 "\xFB" => '&#1099;',
166 "\xFC" => '&#1100;',
167 "\xFD" => '&#1101;',
168 "\xFE" => '&#1102;',
169 "\xFF" => '&#1103;'
170 );
171
172 $string = str_replace(array_keys($cp1251), array_values($cp1251), $string);
173
174 return $string;
175}
176
d6c32258 177?>