Makes managing decoding easier. Mac decoding moved to separate cvs module
[squirrelmail.git] / functions / decode / cp1256.php
1 <?php
2 /**
3 * decode/cp1256.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 cp1256 decoding function that is needed to read
10 * cp1256 encoded mails in non-cp1256 locale.
11 *
12 * Original data taken from:
13 * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1256.TXT
14 *
15 * Name: cp1256 to Unicode table
16 * Unicode version: 2.1
17 * Table version: 2.01
18 * Table format: Format A
19 * Date: 01/5/99
20 * Contact: cpxlate@microsoft.com
21 * @package squirrelmail
22 * @subpackage decode
23 */
24
25 /**
26 * decode cp1256-encoded string
27 * @param string $string Encoded string
28 * @return string $string Decoded string
29 */
30 function charset_decode_cp1256 ($string) {
31 global $default_charset;
32
33 if (strtolower($default_charset) == 'windows-1256')
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 $cp1256 = array(
42 "\x80" => '&#8364;',
43 "\x81" => '&#1662;',
44 "\x82" => '&#8218;',
45 "\x83" => '&#402;',
46 "\x84" => '&#8222;',
47 "\x85" => '&#8230;',
48 "\x86" => '&#8224;',
49 "\x87" => '&#8225;',
50 "\x88" => '&#710;',
51 "\x89" => '&#8240;',
52 "\x8A" => '&#1657;',
53 "\x8B" => '&#8249;',
54 "\x8C" => '&#338;',
55 "\x8D" => '&#1670;',
56 "\x8E" => '&#1688;',
57 "\x8F" => '&#1672;',
58 "\x90" => '&#1711;',
59 "\x91" => '&#8216;',
60 "\x92" => '&#8217;',
61 "\x93" => '&#8220;',
62 "\x94" => '&#8221;',
63 "\x95" => '&#8226;',
64 "\x96" => '&#8211;',
65 "\x97" => '&#8212;',
66 "\x98" => '&#1705;',
67 "\x99" => '&#8482;',
68 "\x9A" => '&#1681;',
69 "\x9B" => '&#8250;',
70 "\x9C" => '&#339;',
71 "\x9D" => '&#8204;',
72 "\x9E" => '&#8205;',
73 "\x9F" => '&#1722;',
74 "\xA0" => '&#160;',
75 "\xA1" => '&#1548;',
76 "\xA2" => '&#162;',
77 "\xA3" => '&#163;',
78 "\xA4" => '&#164;',
79 "\xA5" => '&#165;',
80 "\xA6" => '&#166;',
81 "\xA7" => '&#167;',
82 "\xA8" => '&#168;',
83 "\xA9" => '&#169;',
84 "\xAA" => '&#1726;',
85 "\xAB" => '&#171;',
86 "\xAC" => '&#172;',
87 "\xAD" => '&#173;',
88 "\xAE" => '&#174;',
89 "\xAF" => '&#175;',
90 "\xB0" => '&#176;',
91 "\xB1" => '&#177;',
92 "\xB2" => '&#178;',
93 "\xB3" => '&#179;',
94 "\xB4" => '&#180;',
95 "\xB5" => '&#181;',
96 "\xB6" => '&#182;',
97 "\xB7" => '&#183;',
98 "\xB8" => '&#184;',
99 "\xB9" => '&#185;',
100 "\xBA" => '&#1563;',
101 "\xBB" => '&#187;',
102 "\xBC" => '&#188;',
103 "\xBD" => '&#189;',
104 "\xBE" => '&#190;',
105 "\xBF" => '&#1567;',
106 "\xC0" => '&#1729;',
107 "\xC1" => '&#1569;',
108 "\xC2" => '&#1570;',
109 "\xC3" => '&#1571;',
110 "\xC4" => '&#1572;',
111 "\xC5" => '&#1573;',
112 "\xC6" => '&#1574;',
113 "\xC7" => '&#1575;',
114 "\xC8" => '&#1576;',
115 "\xC9" => '&#1577;',
116 "\xCA" => '&#1578;',
117 "\xCB" => '&#1579;',
118 "\xCC" => '&#1580;',
119 "\xCD" => '&#1581;',
120 "\xCE" => '&#1582;',
121 "\xCF" => '&#1583;',
122 "\xD0" => '&#1584;',
123 "\xD1" => '&#1585;',
124 "\xD2" => '&#1586;',
125 "\xD3" => '&#1587;',
126 "\xD4" => '&#1588;',
127 "\xD5" => '&#1589;',
128 "\xD6" => '&#1590;',
129 "\xD7" => '&#215;',
130 "\xD8" => '&#1591;',
131 "\xD9" => '&#1592;',
132 "\xDA" => '&#1593;',
133 "\xDB" => '&#1594;',
134 "\xDC" => '&#1600;',
135 "\xDD" => '&#1601;',
136 "\xDE" => '&#1602;',
137 "\xDF" => '&#1603;',
138 "\xE0" => '&#224;',
139 "\xE1" => '&#1604;',
140 "\xE2" => '&#226;',
141 "\xE3" => '&#1605;',
142 "\xE4" => '&#1606;',
143 "\xE5" => '&#1607;',
144 "\xE6" => '&#1608;',
145 "\xE7" => '&#231;',
146 "\xE8" => '&#232;',
147 "\xE9" => '&#233;',
148 "\xEA" => '&#234;',
149 "\xEB" => '&#235;',
150 "\xEC" => '&#1609;',
151 "\xED" => '&#1610;',
152 "\xEE" => '&#238;',
153 "\xEF" => '&#239;',
154 "\xF0" => '&#1611;',
155 "\xF1" => '&#1612;',
156 "\xF2" => '&#1613;',
157 "\xF3" => '&#1614;',
158 "\xF4" => '&#244;',
159 "\xF5" => '&#1615;',
160 "\xF6" => '&#1616;',
161 "\xF7" => '&#247;',
162 "\xF8" => '&#1617;',
163 "\xF9" => '&#249;',
164 "\xFA" => '&#1618;',
165 "\xFB" => '&#251;',
166 "\xFC" => '&#252;',
167 "\xFD" => '&#8206;',
168 "\xFE" => '&#8207;',
169 "\xFF" => '&#1746;'
170 );
171
172 $string = str_replace(array_keys($cp1256), array_values($cp1256), $string);
173
174 return $string;
175 }
176
177 ?>