| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * i18n.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This file contains variuos functions that are needed to do |
| 10 | * internationalization of SquirrelMail. |
| 11 | * |
| 12 | * Internally the output character set is used. Other characters are |
| 13 | * encoded using Unicode entities according to HTML 4.0. |
| 14 | * |
| 15 | * $Id$ |
| 16 | */ |
| 17 | |
| 18 | require_once(SM_PATH . 'functions/global.php'); |
| 19 | |
| 20 | /* Decodes a string to the internal encoding from the given charset */ |
| 21 | function charset_decode ($charset, $string) { |
| 22 | global $languages, $squirrelmail_language; |
| 23 | |
| 24 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
| 25 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
| 26 | $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string); |
| 27 | } |
| 28 | |
| 29 | /* All HTML special characters are 7 bit and can be replaced first */ |
| 30 | |
| 31 | $string = htmlspecialchars ($string); |
| 32 | |
| 33 | $charset = strtolower($charset); |
| 34 | |
| 35 | set_my_charset() ; |
| 36 | |
| 37 | if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) { |
| 38 | if ($res[1] == '1') { |
| 39 | $ret = charset_decode_iso_8859_1 ($string); |
| 40 | } else if ($res[1] == '2') { |
| 41 | $ret = charset_decode_iso_8859_2 ($string); |
| 42 | } else if ($res[1] == '4') { |
| 43 | $ret = charset_decode_iso_8859_4 ($string); |
| 44 | } else if ($res[1] == '5') { |
| 45 | $ret = charset_decode_iso_8859_5 ($string); |
| 46 | } else if ($res[1] == '6') { |
| 47 | $ret = charset_decode_iso_8859_6 ($string); |
| 48 | } else if ($res[1] == '7') { |
| 49 | $ret = charset_decode_iso_8859_7 ($string); |
| 50 | } else if ($res[1] == '9') { |
| 51 | $ret = charset_decode_iso_8859_9 ($string); |
| 52 | } else if ($res[1] == '13') { |
| 53 | $ret = charset_decode_iso_8859_13 ($string); |
| 54 | } else if ($res[1] == '15') { |
| 55 | $ret = charset_decode_iso_8859_15 ($string); |
| 56 | } else { |
| 57 | $ret = charset_decode_iso_8859_default ($string); |
| 58 | } |
| 59 | } else if ($charset == 'ns_4551-1') { |
| 60 | $ret = charset_decode_ns_4551_1 ($string); |
| 61 | } else if ($charset == 'koi8-r') { |
| 62 | $ret = charset_decode_koi8r ($string); |
| 63 | } else if ($charset == 'koi8-u') { |
| 64 | $ret = charset_decode_koi8u ($string); |
| 65 | } else if ($charset == 'windows-1251') { |
| 66 | $ret = charset_decode_windows_1251 ($string); |
| 67 | } else if ($charset == 'windows-1253') { |
| 68 | $ret = charset_decode_windows_1253 ($string); |
| 69 | } else if ($charset == 'windows-1254') { |
| 70 | $ret = charset_decode_windows_1254 ($string); |
| 71 | } else if ($charset == 'windows-1255') { |
| 72 | $ret = charset_decode_windows_1255 ($string); |
| 73 | } else if ($charset == 'windows-1256') { |
| 74 | $ret = charset_decode_windows_1256 ($string); |
| 75 | } else if ($charset == 'windows-1257') { |
| 76 | $ret = charset_decode_windows_1257 ($string); |
| 77 | } else if ($charset == 'utf-8') { |
| 78 | $ret = charset_decode_utf8 ($string); |
| 79 | } else { |
| 80 | $ret = $string; |
| 81 | } |
| 82 | return( $ret ); |
| 83 | } |
| 84 | |
| 85 | /* |
| 86 | iso-8859-1 is the same as Latin 1 and is normally used |
| 87 | in western europe. |
| 88 | */ |
| 89 | function charset_decode_iso_8859_1 ($string) { |
| 90 | global $default_charset; |
| 91 | |
| 92 | if (strtolower($default_charset) <> 'iso-8859-1') { |
| 93 | /* Only do the slow convert if there are 8-bit characters */ |
| 94 | if (ereg("[\200-\377]", $string)) { |
| 95 | $string = str_replace("\201", '', $string); |
| 96 | $string = str_replace("\202", '‚', $string); |
| 97 | $string = str_replace("\203", 'ƒ', $string); |
| 98 | $string = str_replace("\204", '„', $string); |
| 99 | $string = str_replace("\205", '…', $string); |
| 100 | $string = str_replace("\206", '†', $string); |
| 101 | $string = str_replace("\207", '‡', $string); |
| 102 | $string = str_replace("\210", 'ˆ', $string); |
| 103 | $string = str_replace("\211", '‰', $string); |
| 104 | $string = str_replace("\212", 'Š', $string); |
| 105 | $string = str_replace("\213", '‹', $string); |
| 106 | $string = str_replace("\214", 'Œ', $string); |
| 107 | $string = str_replace("\215", '', $string); |
| 108 | $string = str_replace("\216", 'Ž', $string); |
| 109 | $string = str_replace("\217", '', $string); |
| 110 | $string = str_replace("\220", '', $string); |
| 111 | $string = str_replace("\221", '‘', $string); |
| 112 | $string = str_replace("\222", '’', $string); |
| 113 | $string = str_replace("\223", '“', $string); |
| 114 | $string = str_replace("\224", '”', $string); |
| 115 | $string = str_replace("\225", '•', $string); |
| 116 | $string = str_replace("\226", '–', $string); |
| 117 | $string = str_replace("\227", '—', $string); |
| 118 | $string = str_replace("\230", '˜', $string); |
| 119 | $string = str_replace("\231", '™', $string); |
| 120 | $string = str_replace("\232", 'š', $string); |
| 121 | $string = str_replace("\233", '›', $string); |
| 122 | $string = str_replace("\234", 'œ', $string); |
| 123 | $string = str_replace("\235", '', $string); |
| 124 | $string = str_replace("\236", 'ž', $string); |
| 125 | $string = str_replace("\237", 'Ÿ', $string); |
| 126 | $string = str_replace("\240", ' ', $string); |
| 127 | $string = str_replace("\241", '¡', $string); |
| 128 | $string = str_replace("\242", '¢', $string); |
| 129 | $string = str_replace("\243", '£', $string); |
| 130 | $string = str_replace("\244", '¤', $string); |
| 131 | $string = str_replace("\245", '¥', $string); |
| 132 | $string = str_replace("\246", '¦', $string); |
| 133 | $string = str_replace("\247", '§', $string); |
| 134 | $string = str_replace("\250", '¨', $string); |
| 135 | $string = str_replace("\251", '©', $string); |
| 136 | $string = str_replace("\252", 'ª', $string); |
| 137 | $string = str_replace("\253", '«', $string); |
| 138 | $string = str_replace("\254", '¬', $string); |
| 139 | $string = str_replace("\255", '­', $string); |
| 140 | $string = str_replace("\256", '®', $string); |
| 141 | $string = str_replace("\257", '¯', $string); |
| 142 | $string = str_replace("\260", '°', $string); |
| 143 | $string = str_replace("\261", '±', $string); |
| 144 | $string = str_replace("\262", '²', $string); |
| 145 | $string = str_replace("\263", '³', $string); |
| 146 | $string = str_replace("\264", '´', $string); |
| 147 | $string = str_replace("\265", 'µ', $string); |
| 148 | $string = str_replace("\266", '¶', $string); |
| 149 | $string = str_replace("\267", '·', $string); |
| 150 | $string = str_replace("\270", '¸', $string); |
| 151 | $string = str_replace("\271", '¹', $string); |
| 152 | $string = str_replace("\272", 'º', $string); |
| 153 | $string = str_replace("\273", '»', $string); |
| 154 | $string = str_replace("\274", '¼', $string); |
| 155 | $string = str_replace("\275", '½', $string); |
| 156 | $string = str_replace("\276", '¾', $string); |
| 157 | $string = str_replace("\277", '¿', $string); |
| 158 | $string = str_replace("\300", 'À', $string); |
| 159 | $string = str_replace("\301", 'Á', $string); |
| 160 | $string = str_replace("\302", 'Â', $string); |
| 161 | $string = str_replace("\303", 'Ã', $string); |
| 162 | $string = str_replace("\304", 'Ä', $string); |
| 163 | $string = str_replace("\305", 'Å', $string); |
| 164 | $string = str_replace("\306", 'Æ', $string); |
| 165 | $string = str_replace("\307", 'Ç', $string); |
| 166 | $string = str_replace("\310", 'È', $string); |
| 167 | $string = str_replace("\311", 'É', $string); |
| 168 | $string = str_replace("\312", 'Ê', $string); |
| 169 | $string = str_replace("\313", 'Ë', $string); |
| 170 | $string = str_replace("\314", 'Ì', $string); |
| 171 | $string = str_replace("\315", 'Í', $string); |
| 172 | $string = str_replace("\316", 'Î', $string); |
| 173 | $string = str_replace("\317", 'Ï', $string); |
| 174 | $string = str_replace("\320", 'Ð', $string); |
| 175 | $string = str_replace("\321", 'Ñ', $string); |
| 176 | $string = str_replace("\322", 'Ò', $string); |
| 177 | $string = str_replace("\323", 'Ó', $string); |
| 178 | $string = str_replace("\324", 'Ô', $string); |
| 179 | $string = str_replace("\325", 'Õ', $string); |
| 180 | $string = str_replace("\326", 'Ö', $string); |
| 181 | $string = str_replace("\327", '×', $string); |
| 182 | $string = str_replace("\330", 'Ø', $string); |
| 183 | $string = str_replace("\331", 'Ù', $string); |
| 184 | $string = str_replace("\332", 'Ú', $string); |
| 185 | $string = str_replace("\333", 'Û', $string); |
| 186 | $string = str_replace("\334", 'Ü', $string); |
| 187 | $string = str_replace("\335", 'Ý', $string); |
| 188 | $string = str_replace("\336", 'Þ', $string); |
| 189 | $string = str_replace("\337", 'ß', $string); |
| 190 | $string = str_replace("\340", 'à', $string); |
| 191 | $string = str_replace("\341", 'á', $string); |
| 192 | $string = str_replace("\342", 'â', $string); |
| 193 | $string = str_replace("\343", 'ã', $string); |
| 194 | $string = str_replace("\344", 'ä', $string); |
| 195 | $string = str_replace("\345", 'å', $string); |
| 196 | $string = str_replace("\346", 'æ', $string); |
| 197 | $string = str_replace("\347", 'ç', $string); |
| 198 | $string = str_replace("\350", 'è', $string); |
| 199 | $string = str_replace("\351", 'é', $string); |
| 200 | $string = str_replace("\352", 'ê', $string); |
| 201 | $string = str_replace("\353", 'ë', $string); |
| 202 | $string = str_replace("\354", 'ì', $string); |
| 203 | $string = str_replace("\355", 'í', $string); |
| 204 | $string = str_replace("\356", 'î', $string); |
| 205 | $string = str_replace("\357", 'ï', $string); |
| 206 | $string = str_replace("\360", 'ð', $string); |
| 207 | $string = str_replace("\361", 'ñ', $string); |
| 208 | $string = str_replace("\362", 'ò', $string); |
| 209 | $string = str_replace("\363", 'ó', $string); |
| 210 | $string = str_replace("\364", 'ô', $string); |
| 211 | $string = str_replace("\365", 'õ', $string); |
| 212 | $string = str_replace("\366", 'ö', $string); |
| 213 | $string = str_replace("\367", '÷', $string); |
| 214 | $string = str_replace("\370", 'ø', $string); |
| 215 | $string = str_replace("\371", 'ù', $string); |
| 216 | $string = str_replace("\372", 'ú', $string); |
| 217 | $string = str_replace("\373", 'û', $string); |
| 218 | $string = str_replace("\374", 'ü', $string); |
| 219 | $string = str_replace("\375", 'ý', $string); |
| 220 | $string = str_replace("\376", 'þ', $string); |
| 221 | $string = str_replace("\377", 'ÿ', $string); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | return ($string); |
| 226 | } |
| 227 | |
| 228 | /* iso-8859-2 is used for some eastern European languages */ |
| 229 | function charset_decode_iso_8859_2 ($string) { |
| 230 | global $default_charset; |
| 231 | |
| 232 | if (strtolower($default_charset) == 'iso-8859-2') |
| 233 | return $string; |
| 234 | |
| 235 | /* Only do the slow convert if there are 8-bit characters */ |
| 236 | if (! ereg("[\200-\377]", $string)) |
| 237 | return $string; |
| 238 | |
| 239 | /* NO-BREAK SPACE */ |
| 240 | $string = str_replace("\240", ' ', $string); |
| 241 | /* LATIN CAPITAL LETTER A WITH OGONEK */ |
| 242 | $string = str_replace("\241", 'Ą', $string); |
| 243 | /* BREVE */ |
| 244 | $string = str_replace("\242", '˘', $string); |
| 245 | // LATIN CAPITAL LETTER L WITH STROKE |
| 246 | $string = str_replace("\243", 'Ł', $string); |
| 247 | // CURRENCY SIGN |
| 248 | $string = str_replace("\244", '¤', $string); |
| 249 | // LATIN CAPITAL LETTER L WITH CARON |
| 250 | $string = str_replace("\245", 'Ľ', $string); |
| 251 | // LATIN CAPITAL LETTER S WITH ACUTE |
| 252 | $string = str_replace("\246", 'Ś', $string); |
| 253 | // SECTION SIGN |
| 254 | $string = str_replace("\247", '§', $string); |
| 255 | // DIAERESIS |
| 256 | $string = str_replace("\250", '¨', $string); |
| 257 | // LATIN CAPITAL LETTER S WITH CARON |
| 258 | $string = str_replace("\251", 'Š', $string); |
| 259 | // LATIN CAPITAL LETTER S WITH CEDILLA |
| 260 | $string = str_replace("\252", 'Ş', $string); |
| 261 | // LATIN CAPITAL LETTER T WITH CARON |
| 262 | $string = str_replace("\253", 'Ť', $string); |
| 263 | // LATIN CAPITAL LETTER Z WITH ACUTE |
| 264 | $string = str_replace("\254", 'Ź', $string); |
| 265 | // SOFT HYPHEN |
| 266 | $string = str_replace("\255", '­', $string); |
| 267 | // LATIN CAPITAL LETTER Z WITH CARON |
| 268 | $string = str_replace("\256", 'Ž', $string); |
| 269 | // LATIN CAPITAL LETTER Z WITH DOT ABOVE |
| 270 | $string = str_replace("\257", 'Ż', $string); |
| 271 | // DEGREE SIGN |
| 272 | $string = str_replace("\260", '°', $string); |
| 273 | // LATIN SMALL LETTER A WITH OGONEK |
| 274 | $string = str_replace("\261", 'ą', $string); |
| 275 | // OGONEK |
| 276 | $string = str_replace("\262", '˛', $string); |
| 277 | // LATIN SMALL LETTER L WITH STROKE |
| 278 | $string = str_replace("\263", 'ł', $string); |
| 279 | // ACUTE ACCENT |
| 280 | $string = str_replace("\264", '´', $string); |
| 281 | // LATIN SMALL LETTER L WITH CARON |
| 282 | $string = str_replace("\265", 'ľ', $string); |
| 283 | // LATIN SMALL LETTER S WITH ACUTE |
| 284 | $string = str_replace("\266", 'ś', $string); |
| 285 | // CARON |
| 286 | $string = str_replace("\267", 'ˇ', $string); |
| 287 | // CEDILLA |
| 288 | $string = str_replace("\270", '¸', $string); |
| 289 | // LATIN SMALL LETTER S WITH CARON |
| 290 | $string = str_replace("\271", 'š', $string); |
| 291 | // LATIN SMALL LETTER S WITH CEDILLA |
| 292 | $string = str_replace("\272", 'ş', $string); |
| 293 | // LATIN SMALL LETTER T WITH CARON |
| 294 | $string = str_replace("\273", 'ť', $string); |
| 295 | // LATIN SMALL LETTER Z WITH ACUTE |
| 296 | $string = str_replace("\274", 'ź', $string); |
| 297 | // DOUBLE ACUTE ACCENT |
| 298 | $string = str_replace("\275", '˝', $string); |
| 299 | // LATIN SMALL LETTER Z WITH CARON |
| 300 | $string = str_replace("\276", 'ž', $string); |
| 301 | // LATIN SMALL LETTER Z WITH DOT ABOVE |
| 302 | $string = str_replace("\277", 'ż', $string); |
| 303 | // LATIN CAPITAL LETTER R WITH ACUTE |
| 304 | $string = str_replace("\300", 'Ŕ', $string); |
| 305 | // LATIN CAPITAL LETTER A WITH ACUTE |
| 306 | $string = str_replace("\301", 'Á', $string); |
| 307 | // LATIN CAPITAL LETTER A WITH CIRCUMFLEX |
| 308 | $string = str_replace("\302", 'Â', $string); |
| 309 | // LATIN CAPITAL LETTER A WITH BREVE |
| 310 | $string = str_replace("\303", 'Ă', $string); |
| 311 | // LATIN CAPITAL LETTER A WITH DIAERESIS |
| 312 | $string = str_replace("\304", 'Ä', $string); |
| 313 | // LATIN CAPITAL LETTER L WITH ACUTE |
| 314 | $string = str_replace("\305", 'Ĺ', $string); |
| 315 | // LATIN CAPITAL LETTER C WITH ACUTE |
| 316 | $string = str_replace("\306", 'Ć', $string); |
| 317 | // LATIN CAPITAL LETTER C WITH CEDILLA |
| 318 | $string = str_replace("\307", 'Ç', $string); |
| 319 | // LATIN CAPITAL LETTER C WITH CARON |
| 320 | $string = str_replace("\310", 'Č', $string); |
| 321 | // LATIN CAPITAL LETTER E WITH ACUTE |
| 322 | $string = str_replace("\311", 'É', $string); |
| 323 | // LATIN CAPITAL LETTER E WITH OGONEK |
| 324 | $string = str_replace("\312", 'Ę', $string); |
| 325 | // LATIN CAPITAL LETTER E WITH DIAERESIS |
| 326 | $string = str_replace("\313", 'Ë', $string); |
| 327 | // LATIN CAPITAL LETTER E WITH CARON |
| 328 | $string = str_replace("\314", 'Ě', $string); |
| 329 | // LATIN CAPITAL LETTER I WITH ACUTE |
| 330 | $string = str_replace("\315", 'Í', $string); |
| 331 | // LATIN CAPITAL LETTER I WITH CIRCUMFLEX |
| 332 | $string = str_replace("\316", 'Î', $string); |
| 333 | // LATIN CAPITAL LETTER D WITH CARON |
| 334 | $string = str_replace("\317", 'Ď', $string); |
| 335 | // LATIN CAPITAL LETTER D WITH STROKE |
| 336 | $string = str_replace("\320", 'Đ', $string); |
| 337 | // LATIN CAPITAL LETTER N WITH ACUTE |
| 338 | $string = str_replace("\321", 'Ń', $string); |
| 339 | // LATIN CAPITAL LETTER N WITH CARON |
| 340 | $string = str_replace("\322", 'Ň', $string); |
| 341 | // LATIN CAPITAL LETTER O WITH ACUTE |
| 342 | $string = str_replace("\323", 'Ó', $string); |
| 343 | // LATIN CAPITAL LETTER O WITH CIRCUMFLEX |
| 344 | $string = str_replace("\324", 'Ô', $string); |
| 345 | // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE |
| 346 | $string = str_replace("\325", 'Ő', $string); |
| 347 | // LATIN CAPITAL LETTER O WITH DIAERESIS |
| 348 | $string = str_replace("\326", 'Ö', $string); |
| 349 | // MULTIPLICATION SIGN |
| 350 | $string = str_replace("\327", '×', $string); |
| 351 | // LATIN CAPITAL LETTER R WITH CARON |
| 352 | $string = str_replace("\330", 'Ř', $string); |
| 353 | // LATIN CAPITAL LETTER U WITH RING ABOVE |
| 354 | $string = str_replace("\331", 'Ů', $string); |
| 355 | // LATIN CAPITAL LETTER U WITH ACUTE |
| 356 | $string = str_replace("\332", 'Ú', $string); |
| 357 | // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE |
| 358 | $string = str_replace("\333", 'Ű', $string); |
| 359 | // LATIN CAPITAL LETTER U WITH DIAERESIS |
| 360 | $string = str_replace("\334", 'Ü', $string); |
| 361 | // LATIN CAPITAL LETTER Y WITH ACUTE |
| 362 | $string = str_replace("\335", 'Ý', $string); |
| 363 | // LATIN CAPITAL LETTER T WITH CEDILLA |
| 364 | $string = str_replace("\336", 'Ţ', $string); |
| 365 | // LATIN SMALL LETTER SHARP S |
| 366 | $string = str_replace("\337", 'ß', $string); |
| 367 | // LATIN SMALL LETTER R WITH ACUTE |
| 368 | $string = str_replace("\340", 'ŕ', $string); |
| 369 | // LATIN SMALL LETTER A WITH ACUTE |
| 370 | $string = str_replace("\341", 'á', $string); |
| 371 | // LATIN SMALL LETTER A WITH CIRCUMFLEX |
| 372 | $string = str_replace("\342", 'â', $string); |
| 373 | // LATIN SMALL LETTER A WITH BREVE |
| 374 | $string = str_replace("\343", 'ă', $string); |
| 375 | // LATIN SMALL LETTER A WITH DIAERESIS |
| 376 | $string = str_replace("\344", 'ä', $string); |
| 377 | // LATIN SMALL LETTER L WITH ACUTE |
| 378 | $string = str_replace("\345", 'ĺ', $string); |
| 379 | // LATIN SMALL LETTER C WITH ACUTE |
| 380 | $string = str_replace("\346", 'ć', $string); |
| 381 | // LATIN SMALL LETTER C WITH CEDILLA |
| 382 | $string = str_replace("\347", 'ç', $string); |
| 383 | // LATIN SMALL LETTER C WITH CARON |
| 384 | $string = str_replace("\350", 'č', $string); |
| 385 | // LATIN SMALL LETTER E WITH ACUTE |
| 386 | $string = str_replace("\351", 'é', $string); |
| 387 | // LATIN SMALL LETTER E WITH OGONEK |
| 388 | $string = str_replace("\352", 'ę', $string); |
| 389 | // LATIN SMALL LETTER E WITH DIAERESIS |
| 390 | $string = str_replace("\353", 'ë', $string); |
| 391 | // LATIN SMALL LETTER E WITH CARON |
| 392 | $string = str_replace("\354", 'ě', $string); |
| 393 | // LATIN SMALL LETTER I WITH ACUTE |
| 394 | $string = str_replace("\355", 'í', $string); |
| 395 | // LATIN SMALL LETTER I WITH CIRCUMFLEX |
| 396 | $string = str_replace("\356", 'î', $string); |
| 397 | // LATIN SMALL LETTER D WITH CARON |
| 398 | $string = str_replace("\357", 'ď', $string); |
| 399 | // LATIN SMALL LETTER D WITH STROKE |
| 400 | $string = str_replace("\360", 'đ', $string); |
| 401 | // LATIN SMALL LETTER N WITH ACUTE |
| 402 | $string = str_replace("\361", 'ń', $string); |
| 403 | // LATIN SMALL LETTER N WITH CARON |
| 404 | $string = str_replace("\362", 'ň', $string); |
| 405 | // LATIN SMALL LETTER O WITH ACUTE |
| 406 | $string = str_replace("\363", 'ó', $string); |
| 407 | // LATIN SMALL LETTER O WITH CIRCUMFLEX |
| 408 | $string = str_replace("\364", 'ô', $string); |
| 409 | // LATIN SMALL LETTER O WITH DOUBLE ACUTE |
| 410 | $string = str_replace("\365", 'ő', $string); |
| 411 | // LATIN SMALL LETTER O WITH DIAERESIS |
| 412 | $string = str_replace("\366", 'ö', $string); |
| 413 | // DIVISION SIGN |
| 414 | $string = str_replace("\367", '÷', $string); |
| 415 | // LATIN SMALL LETTER R WITH CARON |
| 416 | $string = str_replace("\370", 'ř', $string); |
| 417 | // LATIN SMALL LETTER U WITH RING ABOVE |
| 418 | $string = str_replace("\371", 'ů', $string); |
| 419 | // LATIN SMALL LETTER U WITH ACUTE |
| 420 | $string = str_replace("\372", 'ú', $string); |
| 421 | // LATIN SMALL LETTER U WITH DOUBLE ACUTE |
| 422 | $string = str_replace("\373", 'ű', $string); |
| 423 | // LATIN SMALL LETTER U WITH DIAERESIS |
| 424 | $string = str_replace("\374", 'ü', $string); |
| 425 | // LATIN SMALL LETTER Y WITH ACUTE |
| 426 | $string = str_replace("\375", 'ý', $string); |
| 427 | // LATIN SMALL LETTER T WITH CEDILLA |
| 428 | $string = str_replace("\376", 'ţ', $string); |
| 429 | // DOT ABOVE |
| 430 | $string = str_replace("\377", '˙', $string); |
| 431 | |
| 432 | return $string; |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | ISO/IEC 8859-4:1998 Latin Alphabet No. 4 |
| 437 | */ |
| 438 | |
| 439 | function charset_decode_iso_8859_4 ($string) { |
| 440 | global $default_charset; |
| 441 | |
| 442 | if (strtolower($default_charset) == 'iso-8859-4') |
| 443 | return $string; |
| 444 | |
| 445 | /* Only do the slow convert if there are 8-bit characters */ |
| 446 | if (! ereg("[\200-\377]", $string)) |
| 447 | return $string; |
| 448 | |
| 449 | $string = str_replace ("\241", 'Ą', $string); |
| 450 | $string = str_replace ("\242", 'ĸ', $string); |
| 451 | $string = str_replace ("\243", 'Ŗ', $string); |
| 452 | $string = str_replace ("\245", 'Ĩ', $string); |
| 453 | $string = str_replace ("\246", 'Ļ', $string); |
| 454 | $string = str_replace ("\251", 'Š', $string); |
| 455 | $string = str_replace ("\252", 'Ē', $string); |
| 456 | $string = str_replace ("\253", 'Ģ', $string); |
| 457 | $string = str_replace ("\254", 'Ŧ', $string); |
| 458 | $string = str_replace ("\256", 'Ž', $string); |
| 459 | $string = str_replace ("\261", 'ą', $string); |
| 460 | $string = str_replace ("\262", '˛', $string); |
| 461 | $string = str_replace ("\263", 'ŗ', $string); |
| 462 | $string = str_replace ("\265", 'ĩ', $string); |
| 463 | $string = str_replace ("\266", 'ļ', $string); |
| 464 | $string = str_replace ("\267", 'ˇ', $string); |
| 465 | $string = str_replace ("\271", 'š', $string); |
| 466 | $string = str_replace ("\272", 'ē', $string); |
| 467 | $string = str_replace ("\273", 'ģ', $string); |
| 468 | $string = str_replace ("\274", 'ŧ', $string); |
| 469 | $string = str_replace ("\275", 'Ŋ', $string); |
| 470 | $string = str_replace ("\276", 'ž', $string); |
| 471 | $string = str_replace ("\277", 'ŋ', $string); |
| 472 | $string = str_replace ("\300", 'Ā', $string); |
| 473 | $string = str_replace ("\307", 'Į', $string); |
| 474 | $string = str_replace ("\310", 'Č', $string); |
| 475 | $string = str_replace ("\312", 'Ę', $string); |
| 476 | $string = str_replace ("\314", 'Ė', $string); |
| 477 | $string = str_replace ("\317", 'Ī', $string); |
| 478 | $string = str_replace ("\320", 'Đ', $string); |
| 479 | $string = str_replace ("\321", 'Ņ', $string); |
| 480 | $string = str_replace ("\322", 'Ō', $string); |
| 481 | $string = str_replace ("\323", 'Ķ', $string); |
| 482 | $string = str_replace ("\331", 'Ų', $string); |
| 483 | $string = str_replace ("\335", 'Ũ', $string); |
| 484 | $string = str_replace ("\336", 'Ū', $string); |
| 485 | $string = str_replace ("\340", 'ā', $string); |
| 486 | $string = str_replace ("\347", 'į', $string); |
| 487 | $string = str_replace ("\350", 'č', $string); |
| 488 | $string = str_replace ("\352", 'ę', $string); |
| 489 | $string = str_replace ("\354", 'ė', $string); |
| 490 | $string = str_replace ("\357", 'ī', $string); |
| 491 | $string = str_replace ("\360", 'đ', $string); |
| 492 | $string = str_replace ("\361", 'ņ', $string); |
| 493 | $string = str_replace ("\362", 'ō', $string); |
| 494 | $string = str_replace ("\363", 'ķ', $string); |
| 495 | $string = str_replace ("\371", 'ų', $string); |
| 496 | $string = str_replace ("\375", 'ũ', $string); |
| 497 | $string = str_replace ("\376", 'ū', $string); |
| 498 | $string = str_replace ("\377", '˙', $string); |
| 499 | |
| 500 | // rest of charset is the same as ISO-8859-1 |
| 501 | return (charset_decode_iso_8859_1($string)); |
| 502 | } |
| 503 | |
| 504 | /* ISO-8859-5 is Cyrillic */ |
| 505 | function charset_decode_iso_8859_5 ($string) { |
| 506 | global $default_charset; |
| 507 | |
| 508 | if (strtolower($default_charset) == 'iso-8859-5') { |
| 509 | return $string; |
| 510 | } |
| 511 | |
| 512 | /* Only do the slow convert if there are 8-bit characters */ |
| 513 | if (! ereg("[\200-\377]", $string)) |
| 514 | return $string; |
| 515 | |
| 516 | // NO-BREAK SPACE |
| 517 | $string = str_replace("\240", ' ', $string); |
| 518 | // 161-172 -> 1025-1036 (+864) |
| 519 | $string = preg_replace("/([\241-\254])/e","'&#' . (ord('\\1')+864) . ';'",$string); |
| 520 | // SOFT HYPHEN |
| 521 | $string = str_replace("\255", '­', $string); |
| 522 | // 174-239 -> 1038-1103 (+864) |
| 523 | $string = preg_replace("/([\256-\357])/e","'&#' . (ord('\\1')+864) . ';'",$string); |
| 524 | // NUMERO SIGN |
| 525 | $string = str_replace("\360", '№', $string); |
| 526 | // 241-252 -> 1105-1116 (+864) |
| 527 | $string = preg_replace("/([\361-\374])/e","'&#' . (ord('\\1')+864) . ';'",$string); |
| 528 | // SECTION SIGN |
| 529 | $string = str_replace("\375", '§', $string); |
| 530 | // CYRILLIC SMALL LETTER SHORT U (Byelorussian) |
| 531 | $string = str_replace("\376", 'ў', $string); |
| 532 | // CYRILLIC SMALL LETTER DZHE |
| 533 | $string = str_replace("\377", 'џ', $string); |
| 534 | |
| 535 | return $string; |
| 536 | } |
| 537 | |
| 538 | /* |
| 539 | ISO/IEC 8859-6:1999 Latin/Arabic Alphabet |
| 540 | */ |
| 541 | function charset_decode_iso_8859_6 ($string) { |
| 542 | global $default_charset; |
| 543 | |
| 544 | if (strtolower($default_charset) == 'iso-8859-6') |
| 545 | return $string; |
| 546 | |
| 547 | /* Only do the slow convert if there are 8-bit characters */ |
| 548 | if (! ereg("[\200-\377]", $string)) |
| 549 | return $string; |
| 550 | |
| 551 | $string = str_replace ("\240", ' ', $string); |
| 552 | $string = str_replace ("\244", '¤', $string); |
| 553 | $string = str_replace ("\254", '،', $string); |
| 554 | $string = str_replace ("\255", '­', $string); |
| 555 | $string = str_replace ("\273", '؛', $string); |
| 556 | $string = str_replace ("\277", '؟', $string); |
| 557 | // 193-218 -> 1569-1594 (+1376) |
| 558 | $string = preg_replace("/([\301-\332])/e","'&#' . (ord('\\1')+1376).';'",$string); |
| 559 | // 224-242 -> 1600-1618 (+1376) |
| 560 | $string = preg_replace("/([\340-\362])/e","'&#' . (ord('\\1')+1376).';'",$string); |
| 561 | |
| 562 | return ($string); |
| 563 | } |
| 564 | |
| 565 | /* iso-8859-7 is Greek. */ |
| 566 | function charset_decode_iso_8859_7 ($string) { |
| 567 | global $default_charset; |
| 568 | |
| 569 | if (strtolower($default_charset) == 'iso-8859-7') { |
| 570 | return $string; |
| 571 | } |
| 572 | |
| 573 | /* Only do the slow convert if there are 8-bit characters */ |
| 574 | if (!ereg("[\200-\377]", $string)) { |
| 575 | return $string; |
| 576 | } |
| 577 | |
| 578 | /* Some diverse characters in the beginning */ |
| 579 | $string = str_replace("\240", ' ', $string); |
| 580 | $string = str_replace("\241", '‘', $string); |
| 581 | $string = str_replace("\242", '’', $string); |
| 582 | $string = str_replace("\243", '£', $string); |
| 583 | $string = str_replace("\246", '¦', $string); |
| 584 | $string = str_replace("\247", '§', $string); |
| 585 | $string = str_replace("\250", '¨', $string); |
| 586 | $string = str_replace("\251", '©', $string); |
| 587 | $string = str_replace("\253", '«', $string); |
| 588 | $string = str_replace("\254", '¬', $string); |
| 589 | $string = str_replace("\255", '­', $string); |
| 590 | $string = str_replace("\257", '―', $string); |
| 591 | $string = str_replace("\260", '°', $string); |
| 592 | $string = str_replace("\261", '±', $string); |
| 593 | $string = str_replace("\262", '²', $string); |
| 594 | $string = str_replace("\263", '³', $string); |
| 595 | |
| 596 | /* Horizontal bar (parentheki pavla) */ |
| 597 | $string = str_replace ("\257", '―', $string); |
| 598 | |
| 599 | /* |
| 600 | * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6) |
| 601 | * These are Unicode 900-902 |
| 602 | */ |
| 603 | $string = preg_replace("/([\264-\266])/e","'&#' . (ord('\\1')+720);",$string); |
| 604 | |
| 605 | /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */ |
| 606 | $string = str_replace("\267", '·', $string); |
| 607 | |
| 608 | /* |
| 609 | * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA) |
| 610 | * These are Unicode 900-902 |
| 611 | */ |
| 612 | $string = preg_replace("/([\270-\272])/e","'&#' . (ord('\\1')+720);",$string); |
| 613 | |
| 614 | /* |
| 615 | * 11/11 (0xBB) Right angle quotation mark is the same as in |
| 616 | * iso-8859-1 |
| 617 | */ |
| 618 | $string = str_replace("\273", '»', $string); |
| 619 | |
| 620 | /* And now the rest of the charset */ |
| 621 | $string = preg_replace("/([\274-\376])/e","'&#'.(ord('\\1')+720);",$string); |
| 622 | |
| 623 | return $string; |
| 624 | } |
| 625 | |
| 626 | /* |
| 627 | ISOIEC 8859-9:1999 Latin Alphabet No. 5 |
| 628 | |
| 629 | */ |
| 630 | function charset_decode_iso_8859_9 ($string) { |
| 631 | global $default_charset; |
| 632 | |
| 633 | if (strtolower($default_charset) == 'iso-8859-9') |
| 634 | return $string; |
| 635 | |
| 636 | /* Only do the slow convert if there are 8-bit characters */ |
| 637 | if (! ereg("[\200-\377]", $string)) |
| 638 | return $string; |
| 639 | |
| 640 | // latin capital letter g with breve 208->286 |
| 641 | $string = str_replace("\320", 'Ğ', $string); |
| 642 | // latin capital letter i with dot above 221->304 |
| 643 | $string = str_replace("\335", 'İ', $string); |
| 644 | // latin capital letter s with cedilla 222->350 |
| 645 | $string = str_replace("\336", 'Ş', $string); |
| 646 | // latin small letter g with breve 240->287 |
| 647 | $string = str_replace("\360", 'ğ', $string); |
| 648 | // latin small letter dotless i 253->305 |
| 649 | $string = str_replace("\375", 'ı', $string); |
| 650 | // latin small letter s with cedilla 254->351 |
| 651 | $string = str_replace("\376", 'ş', $string); |
| 652 | |
| 653 | // rest of charset is the same as ISO-8859-1 |
| 654 | return (charset_decode_iso_8859_1($string)); |
| 655 | } |
| 656 | |
| 657 | |
| 658 | /* |
| 659 | ISO/IEC 8859-13:1998 Latin Alphabet No. 7 (Baltic Rim) |
| 660 | */ |
| 661 | function charset_decode_iso_8859_13 ($string) { |
| 662 | global $default_charset; |
| 663 | |
| 664 | if (strtolower($default_charset) == 'iso-8859-13') |
| 665 | return $string; |
| 666 | |
| 667 | /* Only do the slow convert if there are 8-bit characters */ |
| 668 | if (! ereg("[\200-\377]", $string)) |
| 669 | return $string; |
| 670 | |
| 671 | $string = str_replace ("\241", '”', $string); |
| 672 | $string = str_replace ("\245", '„', $string); |
| 673 | $string = str_replace ("\250", 'Ø', $string); |
| 674 | $string = str_replace ("\252", 'Ŗ', $string); |
| 675 | $string = str_replace ("\257", 'Æ', $string); |
| 676 | $string = str_replace ("\264", '“', $string); |
| 677 | $string = str_replace ("\270", 'ø', $string); |
| 678 | $string = str_replace ("\272", 'ŗ', $string); |
| 679 | $string = str_replace ("\277", 'æ', $string); |
| 680 | $string = str_replace ("\300", 'Ą', $string); |
| 681 | $string = str_replace ("\301", 'Į', $string); |
| 682 | $string = str_replace ("\302", 'Ā', $string); |
| 683 | $string = str_replace ("\303", 'Ć', $string); |
| 684 | $string = str_replace ("\306", 'Ę', $string); |
| 685 | $string = str_replace ("\307", 'Ē', $string); |
| 686 | $string = str_replace ("\310", 'Č', $string); |
| 687 | $string = str_replace ("\312", 'Ź', $string); |
| 688 | $string = str_replace ("\313", 'Ė', $string); |
| 689 | $string = str_replace ("\314", 'Ģ', $string); |
| 690 | $string = str_replace ("\315", 'Ķ', $string); |
| 691 | $string = str_replace ("\316", 'Ī', $string); |
| 692 | $string = str_replace ("\317", 'Ļ', $string); |
| 693 | $string = str_replace ("\320", 'Š', $string); |
| 694 | $string = str_replace ("\321", 'Ń', $string); |
| 695 | $string = str_replace ("\322", 'Ņ', $string); |
| 696 | $string = str_replace ("\324", 'Ō', $string); |
| 697 | $string = str_replace ("\330", 'Ų', $string); |
| 698 | $string = str_replace ("\331", 'Ł', $string); |
| 699 | $string = str_replace ("\332", 'Ś', $string); |
| 700 | $string = str_replace ("\333", 'Ū', $string); |
| 701 | $string = str_replace ("\335", 'Ż', $string); |
| 702 | $string = str_replace ("\336", 'Ž', $string); |
| 703 | $string = str_replace ("\340", 'ą', $string); |
| 704 | $string = str_replace ("\341", 'į', $string); |
| 705 | $string = str_replace ("\342", 'ā', $string); |
| 706 | $string = str_replace ("\343", 'ć', $string); |
| 707 | $string = str_replace ("\346", 'ę', $string); |
| 708 | $string = str_replace ("\347", 'ē', $string); |
| 709 | $string = str_replace ("\350", 'č', $string); |
| 710 | $string = str_replace ("\352", 'ź', $string); |
| 711 | $string = str_replace ("\353", 'ė', $string); |
| 712 | $string = str_replace ("\354", 'ģ', $string); |
| 713 | $string = str_replace ("\355", 'ķ', $string); |
| 714 | $string = str_replace ("\356", 'ī', $string); |
| 715 | $string = str_replace ("\357", 'ļ', $string); |
| 716 | $string = str_replace ("\360", 'š', $string); |
| 717 | $string = str_replace ("\361", 'ń', $string); |
| 718 | $string = str_replace ("\362", 'ņ', $string); |
| 719 | $string = str_replace ("\364", 'ō', $string); |
| 720 | $string = str_replace ("\370", 'ų', $string); |
| 721 | $string = str_replace ("\371", 'ł', $string); |
| 722 | $string = str_replace ("\372", 'ś', $string); |
| 723 | $string = str_replace ("\373", 'ū', $string); |
| 724 | $string = str_replace ("\375", 'ż', $string); |
| 725 | $string = str_replace ("\376", 'ž', $string); |
| 726 | $string = str_replace ("\377", '’', $string); |
| 727 | |
| 728 | // rest of charset is the same as ISO-8859-1 |
| 729 | return (charset_decode_iso_8859_1($string)); |
| 730 | } |
| 731 | |
| 732 | /* |
| 733 | * iso-8859-15 is Latin 9 and has very much the same use as Latin 1 |
| 734 | * but has the Euro symbol and some characters needed for French. |
| 735 | */ |
| 736 | function charset_decode_iso_8859_15 ($string) { |
| 737 | // Euro sign |
| 738 | $string = str_replace ("\244", '€', $string); |
| 739 | // Latin capital letter S with caron |
| 740 | $string = str_replace ("\246", 'Š', $string); |
| 741 | // Latin small letter s with caron |
| 742 | $string = str_replace ("\250", 'š', $string); |
| 743 | // Latin capital letter Z with caron |
| 744 | $string = str_replace ("\264", 'Ž', $string); |
| 745 | // Latin small letter z with caron |
| 746 | $string = str_replace ("\270", 'ž', $string); |
| 747 | // Latin capital ligature OE |
| 748 | $string = str_replace ("\274", 'Œ', $string); |
| 749 | // Latin small ligature oe |
| 750 | $string = str_replace ("\275", 'œ', $string); |
| 751 | // Latin capital letter Y with diaeresis |
| 752 | $string = str_replace ("\276", 'Ÿ', $string); |
| 753 | |
| 754 | return (charset_decode_iso_8859_1($string)); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | /* Remove all 8 bit characters from all other ISO-8859 character sets */ |
| 759 | function charset_decode_iso_8859_default ($string) { |
| 760 | return (strtr($string, "\240\241\242\243\244\245\246\247". |
| 761 | "\250\251\252\253\254\255\256\257". |
| 762 | "\260\261\262\263\264\265\266\267". |
| 763 | "\270\271\272\273\274\275\276\277". |
| 764 | "\300\301\302\303\304\305\306\307". |
| 765 | "\310\311\312\313\314\315\316\317". |
| 766 | "\320\321\322\323\324\325\326\327". |
| 767 | "\330\331\332\333\334\335\336\337". |
| 768 | "\340\341\342\343\344\345\346\347". |
| 769 | "\350\351\352\353\354\355\356\357". |
| 770 | "\360\361\362\363\364\365\366\367". |
| 771 | "\370\371\372\373\374\375\376\377", |
| 772 | "????????????????????????????????????????". |
| 773 | "????????????????????????????????????????". |
| 774 | "????????????????????????????????????????". |
| 775 | "????????")); |
| 776 | |
| 777 | } |
| 778 | |
| 779 | /* |
| 780 | * This is the same as ISO-646-NO and is used by some |
| 781 | * Microsoft programs when sending Norwegian characters |
| 782 | */ |
| 783 | function charset_decode_ns_4551_1 ($string) { |
| 784 | /* |
| 785 | * These characters are: |
| 786 | * Latin capital letter AE |
| 787 | * Latin capital letter O with stroke |
| 788 | * Latin capital letter A with ring above |
| 789 | * and the same as small letters |
| 790 | */ |
| 791 |