koi8_r.php 4.8 KB

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