koi8-r.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /*
  3. * decode/koi8-r.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 koi8-r decoding function that is needed to read
  10. * koi8-r encoded mails in non-koi8-r locale.
  11. *
  12. * Original data taken from:
  13. * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MISC/KOI8-R.TXT
  14. *
  15. * Name: KOI8-R (RFC1489) to Unicode
  16. * Unicode version: 3.0
  17. * Table version: 1.0
  18. * Table format: Format A
  19. * Date: 18 August 1999
  20. * Authors: Helmut Richter <richter@lrz.de>
  21. *
  22. * Copyright (c) 1991-1999 Unicode, Inc. All Rights reserved.
  23. *
  24. * This file is provided as-is by Unicode, Inc. (The Unicode Consortium).
  25. * No claims are made as to fitness for any particular purpose. No
  26. * warranties of any kind are expressed or implied. The recipient
  27. * agrees to determine applicability of information provided. If this
  28. * file has been provided on optical media by Unicode, Inc., the sole
  29. * remedy for any claim will be exchange of defective media within 90
  30. * days of receipt.
  31. *
  32. * Unicode, Inc. hereby grants the right to freely use the information
  33. * supplied in this file in the creation of products supporting the
  34. * Unicode Standard, and to make copies of this file in any form for
  35. * internal or external distribution as long as this notice remains
  36. * attached.
  37. *
  38. */
  39. function charset_decode_koi8r ($string) {
  40. global $default_charset;
  41. if (strtolower($default_charset) == 'koi8-r')
  42. return $string;
  43. /* Only do the slow convert if there are 8-bit characters */
  44. /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
  45. if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
  46. return $string;
  47. $koi8r = array(
  48. "\x80" => '&#9472;',
  49. "\x81" => '&#9474;',
  50. "\x82" => '&#9484;',
  51. "\x83" => '&#9488;',
  52. "\x84" => '&#9492;',
  53. "\x85" => '&#9496;',
  54. "\x86" => '&#9500;',
  55. "\x87" => '&#9508;',
  56. "\x88" => '&#9516;',
  57. "\x89" => '&#9524;',
  58. "\x8A" => '&#9532;',
  59. "\x8B" => '&#9600;',
  60. "\x8C" => '&#9604;',
  61. "\x8D" => '&#9608;',
  62. "\x8E" => '&#9612;',
  63. "\x8F" => '&#9616;',
  64. "\x90" => '&#9617;',
  65. "\x91" => '&#9618;',
  66. "\x92" => '&#9619;',
  67. "\x93" => '&#8992;',
  68. "\x94" => '&#9632;',
  69. "\x95" => '&#8729;',
  70. "\x96" => '&#8730;',
  71. "\x97" => '&#8776;',
  72. "\x98" => '&#8804;',
  73. "\x99" => '&#8805;',
  74. "\x9A" => '&#160;',
  75. "\x9B" => '&#8993;',
  76. "\x9C" => '&#176;',
  77. "\x9D" => '&#178;',
  78. "\x9E" => '&#183;',
  79. "\x9F" => '&#247;',
  80. "\xA0" => '&#9552;',
  81. "\xA1" => '&#9553;',
  82. "\xA2" => '&#9554;',
  83. "\xA3" => '&#1105;',
  84. "\xA4" => '&#9555;',
  85. "\xA5" => '&#9556;',
  86. "\xA6" => '&#9557;',
  87. "\xA7" => '&#9558;',
  88. "\xA8" => '&#9559;',
  89. "\xA9" => '&#9560;',
  90. "\xAA" => '&#9561;',
  91. "\xAB" => '&#9562;',
  92. "\xAC" => '&#9563;',
  93. "\xAD" => '&#9564;',
  94. "\xAE" => '&#9565;',
  95. "\xAF" => '&#9566;',
  96. "\xB0" => '&#9567;',
  97. "\xB1" => '&#9568;',
  98. "\xB2" => '&#9569;',
  99. "\xB3" => '&#1025;',
  100. "\xB4" => '&#9570;',
  101. "\xB5" => '&#9571;',
  102. "\xB6" => '&#9572;',
  103. "\xB7" => '&#9573;',
  104. "\xB8" => '&#9574;',
  105. "\xB9" => '&#9575;',
  106. "\xBA" => '&#9576;',
  107. "\xBB" => '&#9577;',
  108. "\xBC" => '&#9578;',
  109. "\xBD" => '&#9579;',
  110. "\xBE" => '&#9580;',
  111. "\xBF" => '&#169;',
  112. "\xC0" => '&#1102;',
  113. "\xC1" => '&#1072;',
  114. "\xC2" => '&#1073;',
  115. "\xC3" => '&#1094;',
  116. "\xC4" => '&#1076;',
  117. "\xC5" => '&#1077;',
  118. "\xC6" => '&#1092;',
  119. "\xC7" => '&#1075;',
  120. "\xC8" => '&#1093;',
  121. "\xC9" => '&#1080;',
  122. "\xCA" => '&#1081;',
  123. "\xCB" => '&#1082;',
  124. "\xCC" => '&#1083;',
  125. "\xCD" => '&#1084;',
  126. "\xCE" => '&#1085;',
  127. "\xCF" => '&#1086;',
  128. "\xD0" => '&#1087;',
  129. "\xD1" => '&#1103;',
  130. "\xD2" => '&#1088;',
  131. "\xD3" => '&#1089;',
  132. "\xD4" => '&#1090;',
  133. "\xD5" => '&#1091;',
  134. "\xD6" => '&#1078;',
  135. "\xD7" => '&#1074;',
  136. "\xD8" => '&#1100;',
  137. "\xD9" => '&#1099;',
  138. "\xDA" => '&#1079;',
  139. "\xDB" => '&#1096;',
  140. "\xDC" => '&#1101;',
  141. "\xDD" => '&#1097;',
  142. "\xDE" => '&#1095;',
  143. "\xDF" => '&#1098;',
  144. "\xE0" => '&#1070;',
  145. "\xE1" => '&#1040;',
  146. "\xE2" => '&#1041;',
  147. "\xE3" => '&#1062;',
  148. "\xE4" => '&#1044;',
  149. "\xE5" => '&#1045;',
  150. "\xE6" => '&#1060;',
  151. "\xE7" => '&#1043;',
  152. "\xE8" => '&#1061;',
  153. "\xE9" => '&#1048;',
  154. "\xEA" => '&#1049;',
  155. "\xEB" => '&#1050;',
  156. "\xEC" => '&#1051;',
  157. "\xED" => '&#1052;',
  158. "\xEE" => '&#1053;',
  159. "\xEF" => '&#1054;',
  160. "\xF0" => '&#1055;',
  161. "\xF1" => '&#1071;',
  162. "\xF2" => '&#1056;',
  163. "\xF3" => '&#1057;',
  164. "\xF4" => '&#1058;',
  165. "\xF5" => '&#1059;',
  166. "\xF6" => '&#1046;',
  167. "\xF7" => '&#1042;',
  168. "\xF8" => '&#1068;',
  169. "\xF9" => '&#1067;',
  170. "\xFA" => '&#1047;',
  171. "\xFB" => '&#1064;',
  172. "\xFC" => '&#1069;',
  173. "\xFD" => '&#1065;',
  174. "\xFE" => '&#1063;',
  175. "\xFF" => '&#1066;'
  176. );
  177. $string = str_replace(array_keys($koi8r), array_values($koi8r), $string);
  178. return $string;
  179. }
  180. ?>