56218332214a5c3ab5ef1e9bc23dd91d5ce408e4
[squirrelmail.git] / functions / decode / cp1252.php
1 <?php
2 /**
3 * decode/cp1252.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 cp1252 decoding function that is needed to read
9 * cp1252 encoded mails in non-cp1252 locale.
10 *
11 * Original data taken from:
12 * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT
13 *
14 * Name: cp1252 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 cp1252-encoded string
28 * @param string $string Encoded string
29 * @return string $string Decoded string
30 */
31
32 function charset_decode_cp1252 ($string) {
33 global $default_charset;
34
35 if (strtolower($default_charset) == 'windows-1252')
36 return $string;
37
38 /* Only do the slow convert if there are 8-bit characters */
39 /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
40 if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
41 return $string;
42
43 $cp1252 = array(
44 "\x80" => '&#8364;',
45 "\x81" => '&#65533;',
46 "\x82" => '&#8218;',
47 "\x83" => '&#402;',
48 "\x84" => '&#8222;',
49 "\x85" => '&#8230;',
50 "\x86" => '&#8224;',
51 "\x87" => '&#8225;',
52 "\x88" => '&#710;',
53 "\x89" => '&#8240;',
54 "\x8A" => '&#352;',
55 "\x8B" => '&#8249;',
56 "\x8C" => '&#338;',
57 "\x8D" => '&#65533;',
58 "\x8E" => '&#381;',
59 "\x8F" => '&#65533;',
60 "\x90" => '&#65533;',
61 "\x91" => '&#8216;',
62 "\x92" => '&#8217;',
63 "\x93" => '&#8220;',
64 "\x94" => '&#8221;',
65 "\x95" => '&#8226;',
66 "\x96" => '&#8211;',
67 "\x97" => '&#8212;',
68 "\x98" => '&#732;',
69 "\x99" => '&#8482;',
70 "\x9A" => '&#353;',
71 "\x9B" => '&#8250;',
72 "\x9C" => '&#339;',
73 "\x9D" => '&#65533;',
74 "\x9E" => '&#382;',
75 "\x9F" => '&#376;',
76 "\xA0" => '&#160;',
77 "\xA1" => '&#161;',
78 "\xA2" => '&#162;',
79 "\xA3" => '&#163;',
80 "\xA4" => '&#164;',
81 "\xA5" => '&#165;',
82 "\xA6" => '&#166;',
83 "\xA7" => '&#167;',
84 "\xA8" => '&#168;',
85 "\xA9" => '&#169;',
86 "\xAA" => '&#170;',
87 "\xAB" => '&#171;',
88 "\xAC" => '&#172;',
89 "\xAD" => '&#173;',
90 "\xAE" => '&#174;',
91 "\xAF" => '&#175;',
92 "\xB0" => '&#176;',
93 "\xB1" => '&#177;',
94 "\xB2" => '&#178;',
95 "\xB3" => '&#179;',
96 "\xB4" => '&#180;',
97 "\xB5" => '&#181;',
98 "\xB6" => '&#182;',
99 "\xB7" => '&#183;',
100 "\xB8" => '&#184;',
101 "\xB9" => '&#185;',
102 "\xBA" => '&#186;',
103 "\xBB" => '&#187;',
104 "\xBC" => '&#188;',
105 "\xBD" => '&#189;',
106 "\xBE" => '&#190;',
107 "\xBF" => '&#191;',
108 "\xC0" => '&#192;',
109 "\xC1" => '&#193;',
110 "\xC2" => '&#194;',
111 "\xC3" => '&#195;',
112 "\xC4" => '&#196;',
113 "\xC5" => '&#197;',
114 "\xC6" => '&#198;',
115 "\xC7" => '&#199;',
116 "\xC8" => '&#200;',
117 "\xC9" => '&#201;',
118 "\xCA" => '&#202;',
119 "\xCB" => '&#203;',
120 "\xCC" => '&#204;',
121 "\xCD" => '&#205;',
122 "\xCE" => '&#206;',
123 "\xCF" => '&#207;',
124 "\xD0" => '&#208;',
125 "\xD1" => '&#209;',
126 "\xD2" => '&#210;',
127 "\xD3" => '&#211;',
128 "\xD4" => '&#212;',
129 "\xD5" => '&#213;',
130 "\xD6" => '&#214;',
131 "\xD7" => '&#215;',
132 "\xD8" => '&#216;',
133 "\xD9" => '&#217;',
134 "\xDA" => '&#218;',
135 "\xDB" => '&#219;',
136 "\xDC" => '&#220;',
137 "\xDD" => '&#221;',
138 "\xDE" => '&#222;',
139 "\xDF" => '&#223;',
140 "\xE0" => '&#224;',
141 "\xE1" => '&#225;',
142 "\xE2" => '&#226;',
143 "\xE3" => '&#227;',
144 "\xE4" => '&#228;',
145 "\xE5" => '&#229;',
146 "\xE6" => '&#230;',
147 "\xE7" => '&#231;',
148 "\xE8" => '&#232;',
149 "\xE9" => '&#233;',
150 "\xEA" => '&#234;',
151 "\xEB" => '&#235;',
152 "\xEC" => '&#236;',
153 "\xED" => '&#237;',
154 "\xEE" => '&#238;',
155 "\xEF" => '&#239;',
156 "\xF0" => '&#240;',
157 "\xF1" => '&#241;',
158 "\xF2" => '&#242;',
159 "\xF3" => '&#243;',
160 "\xF4" => '&#244;',
161 "\xF5" => '&#245;',
162 "\xF6" => '&#246;',
163 "\xF7" => '&#247;',
164 "\xF8" => '&#248;',
165 "\xF9" => '&#249;',
166 "\xFA" => '&#250;',
167 "\xFB" => '&#251;',
168 "\xFC" => '&#252;',
169 "\xFD" => '&#253;',
170 "\xFE" => '&#254;',
171 "\xFF" => '&#255;'
172 );
173
174 $string = str_replace(array_keys($cp1252), array_values($cp1252), $string);
175
176 return $string;
177 }
178
179 ?>