using sq_is8bit function instead of ereg. Code reuse and fixes some problems
[squirrelmail.git] / functions / decode / koi8_u.php
CommitLineData
0a708025 1<?php
d6c32258 2/**
0a708025 3 * decode/koi8-u.php
0a708025 4 *
82d304a0 5 * Copyright (c) 2003-2004 The SquirrelMail Project Team
0a708025 6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file contains koi8-u decoding function that is needed to read
9 * koi8-u encoded mails in non-koi8-u locale.
10 *
11 * Original data taken from rfc2319
12 *
13 * Original copyright:
14 *
15 * Copyright (C) The Internet Society (1998). All Rights Reserved.
16 *
17 * This document and translations of it may be copied and furnished to
18 * others, and derivative works that comment on or otherwise explain it
19 * or assist in its implementation may be prepared, copied, published
20 * and distributed, in whole or in part, without restriction of any
21 * kind, provided that the above copyright notice and this paragraph are
22 * included on all such copies and derivative works. However, this
23 * document itself may not be modified in any way, such as by removing
24 * the copyright notice or references to the Internet Society or other
25 * Internet organizations, except as needed for the purpose of
26 * developing Internet standards in which case the procedures for
27 * copyrights defined in the Internet Standards process must be
28 * followed, or as required to translate it into languages other than
29 * English.
30 *
31 * The limited permissions granted above are perpetual and will not be
32 * revoked by the Internet Society or its successors or assigns.
33 *
34 * This document and the information contained herein is provided on an
35 * "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
36 * TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
37 * BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
38 * HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
39 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
40 *
31841a9e 41 * @version $Id$
d6c32258 42 * @package squirrelmail
43 * @subpackage decode
44 */
45
46/**
47 * Decode koi8-u encoded strings
48 * @param string $string Encoded string
49 * @return string Decoded string
0a708025 50 */
df8c4d6d 51function charset_decode_koi8_u ($string) {
0a708025 52 global $default_charset;
53
54 if (strtolower($default_charset) == 'koi8-u')
55 return $string;
56
e53c9681 57 // don't do decoding when there are no 8bit symbols
58 if (! sq_is8bit($string,'koi8-u'))
0a708025 59 return $string;
60
61 $koi8u = array(
e53c9681 62 "\x80" => '&#9472;',
63 "\x81" => '&#9474;',
64 "\x82" => '&#9484;',
65 "\x83" => '&#9488;',
66 "\x84" => '&#9492;',
67 "\x85" => '&#9496;',
68 "\x86" => '&#9500;',
69 "\x87" => '&#9508;',
70 "\x88" => '&#9516;',
71 "\x89" => '&#9524;',
72 "\x8A" => '&#9532;',
73 "\x8B" => '&#9600;',
74 "\x8C" => '&#9604;',
75 "\x8D" => '&#9608;',
76 "\x8E" => '&#9612;',
77 "\x8F" => '&#9616;',
78 "\x90" => '&#9617;',
79 "\x91" => '&#9618;',
80 "\x92" => '&#9619;',
81 "\x93" => '&#8992;',
82 "\x94" => '&#9632;',
83 "\x95" => '&#8729;',
84 "\x96" => '&#8730;',
85 "\x97" => '&#8776;',
86 "\x98" => '&#8804;',
87 "\x99" => '&#8805;',
88 "\x9A" => '&#160;',
89 "\x9B" => '&#8993;',
90 "\x9C" => '&#176;',
91 "\x9D" => '&#178;',
92 "\x9E" => '&#183;',
93 "\x9F" => '&#247;',
94 "\xA0" => '&#9552;',
95 "\xA1" => '&#9553;',
96 "\xA2" => '&#9554;',
97 "\xA3" => '&#1105;',
98 "\xA4" => '&#1108;',
99 "\xA5" => '&#9556;',
100 "\xA6" => '&#1110;',
101 "\xA7" => '&#1111;',
102 "\xA8" => '&#9559;',
103 "\xA9" => '&#9560;',
104 "\xAA" => '&#9561;',
105 "\xAB" => '&#9562;',
106 "\xAC" => '&#9563;',
107 "\xAD" => '&#1169;',
108 "\xAE" => '&#9565;',
109 "\xAF" => '&#9566;',
110 "\xB0" => '&#9567;',
111 "\xB1" => '&#9568;',
112 "\xB2" => '&#9569;',
113 "\xB3" => '&#1025;',
114 "\xB4" => '&#1027;',
115 "\xB5" => '&#9571;',
116 "\xB6" => '&#1030;',
117 "\xB7" => '&#1031;',
118 "\xB8" => '&#9574;',
119 "\xB9" => '&#9575;',
120 "\xBA" => '&#9576;',
121 "\xBB" => '&#9577;',
122 "\xBC" => '&#9578;',
123 "\xBD" => '&#1168;',
124 "\xBE" => '&#9580;',
125 "\xBF" => '&#169;',
126 "\xC0" => '&#1102;',
127 "\xC1" => '&#1072;',
128 "\xC2" => '&#1073;',
129 "\xC3" => '&#1094;',
130 "\xC4" => '&#1076;',
131 "\xC5" => '&#1077;',
132 "\xC6" => '&#1092;',
133 "\xC7" => '&#1075;',
134 "\xC8" => '&#1093;',
135 "\xC9" => '&#1080;',
136 "\xCA" => '&#1081;',
137 "\xCB" => '&#1082;',
138 "\xCC" => '&#1083;',
139 "\xCD" => '&#1084;',
140 "\xCE" => '&#1085;',
141 "\xCF" => '&#1086;',
142 "\xD0" => '&#1087;',
143 "\xD1" => '&#1103;',
144 "\xD2" => '&#1088;',
145 "\xD3" => '&#1089;',
146 "\xD4" => '&#1090;',
147 "\xD5" => '&#1091;',
148 "\xD6" => '&#1078;',
149 "\xD7" => '&#1074;',
150 "\xD8" => '&#1100;',
151 "\xD9" => '&#1099;',
152 "\xDA" => '&#1079;',
153 "\xDB" => '&#1096;',
154 "\xDC" => '&#1101;',
155 "\xDD" => '&#1097;',
156 "\xDE" => '&#1095;',
157 "\xDF" => '&#1098;',
158 "\xE0" => '&#1070;',
159 "\xE1" => '&#1040;',
160 "\xE2" => '&#1041;',
161 "\xE3" => '&#1062;',
162 "\xE4" => '&#1044;',
163 "\xE5" => '&#1045;',
164 "\xE6" => '&#1060;',
165 "\xE7" => '&#1043;',
166 "\xE8" => '&#1061;',
167 "\xE9" => '&#1048;',
168 "\xEA" => '&#1049;',
169 "\xEB" => '&#1050;',
170 "\xEC" => '&#1051;',
171 "\xED" => '&#1052;',
172 "\xEE" => '&#1053;',
173 "\xEF" => '&#1054;',
174 "\xF0" => '&#1055;',
175 "\xF1" => '&#1071;',
176 "\xF2" => '&#1056;',
177 "\xF3" => '&#1057;',
178 "\xF4" => '&#1058;',
179 "\xF5" => '&#1059;',
180 "\xF6" => '&#1046;',
181 "\xF7" => '&#1042;',
182 "\xF8" => '&#1068;',
183 "\xF9" => '&#1067;',
184 "\xFA" => '&#1047;',
185 "\xFB" => '&#1064;',
186 "\xFC" => '&#1069;',
187 "\xFD" => '&#1065;',
188 "\xFE" => '&#1063;',
189 "\xFF" => '&#1066;'
0a708025 190 );
191
192 $string = str_replace(array_keys($koi8u), array_values($koi8u), $string);
193
194 return $string;
195}
e53c9681 196?>