koi8_r.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * decode/koi8-r.php
  4. *
  5. * Copyright (c) 2003-2005 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. // don't do decoding when there are no 8bit symbols
  48. if (! sq_is8bit($string,'koi8-r'))
  49. return $string;
  50. $koi8r = array(
  51. "\x80" => '&#9472;',
  52. "\x81" => '&#9474;',
  53. "\x82" => '&#9484;',
  54. "\x83" => '&#9488;',
  55. "\x84" => '&#9492;',
  56. "\x85" => '&#9496;',
  57. "\x86" => '&#9500;',
  58. "\x87" => '&#9508;',
  59. "\x88" => '&#9516;',
  60. "\x89" => '&#9524;',
  61. "\x8A" => '&#9532;',
  62. "\x8B" => '&#9600;',
  63. "\x8C" => '&#9604;',
  64. "\x8D" => '&#9608;',
  65. "\x8E" => '&#9612;',
  66. "\x8F" => '&#9616;',
  67. "\x90" => '&#9617;',
  68. "\x91" => '&#9618;',
  69. "\x92" => '&#9619;',
  70. "\x93" => '&#8992;',
  71. "\x94" => '&#9632;',
  72. "\x95" => '&#8729;',
  73. "\x96" => '&#8730;',
  74. "\x97" => '&#8776;',
  75. "\x98" => '&#8804;',
  76. "\x99" => '&#8805;',
  77. "\x9A" => '&#160;',
  78. "\x9B" => '&#8993;',
  79. "\x9C" => '&#176;',
  80. "\x9D" => '&#178;',
  81. "\x9E" => '&#183;',
  82. "\x9F" => '&#247;',
  83. "\xA0" => '&#9552;',
  84. "\xA1" => '&#9553;',
  85. "\xA2" => '&#9554;',
  86. "\xA3" => '&#1105;',
  87. "\xA4" => '&#9555;',
  88. "\xA5" => '&#9556;',
  89. "\xA6" => '&#9557;',
  90. "\xA7" => '&#9558;',
  91. "\xA8" => '&#9559;',
  92. "\xA9" => '&#9560;',
  93. "\xAA" => '&#9561;',
  94. "\xAB" => '&#9562;',
  95. "\xAC" => '&#9563;',
  96. "\xAD" => '&#9564;',
  97. "\xAE" => '&#9565;',
  98. "\xAF" => '&#9566;',
  99. "\xB0" => '&#9567;',
  100. "\xB1" => '&#9568;',
  101. "\xB2" => '&#9569;',
  102. "\xB3" => '&#1025;',
  103. "\xB4" => '&#9570;',
  104. "\xB5" => '&#9571;',
  105. "\xB6" => '&#9572;',
  106. "\xB7" => '&#9573;',
  107. "\xB8" => '&#9574;',
  108. "\xB9" => '&#9575;',
  109. "\xBA" => '&#9576;',
  110. "\xBB" => '&#9577;',
  111. "\xBC" => '&#9578;',
  112. "\xBD" => '&#9579;',
  113. "\xBE" => '&#9580;',
  114. "\xBF" => '&#169;',
  115. "\xC0" => '&#1102;',
  116. "\xC1" => '&#1072;',
  117. "\xC2" => '&#1073;',
  118. "\xC3" => '&#1094;',
  119. "\xC4" => '&#1076;',
  120. "\xC5" => '&#1077;',
  121. "\xC6" => '&#1092;',
  122. "\xC7" => '&#1075;',
  123. "\xC8" => '&#1093;',
  124. "\xC9" => '&#1080;',
  125. "\xCA" => '&#1081;',
  126. "\xCB" => '&#1082;',
  127. "\xCC" => '&#1083;',
  128. "\xCD" => '&#1084;',
  129. "\xCE" => '&#1085;',
  130. "\xCF" => '&#1086;',
  131. "\xD0" => '&#1087;',
  132. "\xD1" => '&#1103;',
  133. "\xD2" => '&#1088;',
  134. "\xD3" => '&#1089;',
  135. "\xD4" => '&#1090;',
  136. "\xD5" => '&#1091;',
  137. "\xD6" => '&#1078;',
  138. "\xD7" => '&#1074;',
  139. "\xD8" => '&#1100;',
  140. "\xD9" => '&#1099;',
  141. "\xDA" => '&#1079;',
  142. "\xDB" => '&#1096;',
  143. "\xDC" => '&#1101;',
  144. "\xDD" => '&#1097;',
  145. "\xDE" => '&#1095;',
  146. "\xDF" => '&#1098;',
  147. "\xE0" => '&#1070;',
  148. "\xE1" => '&#1040;',
  149. "\xE2" => '&#1041;',
  150. "\xE3" => '&#1062;',
  151. "\xE4" => '&#1044;',
  152. "\xE5" => '&#1045;',
  153. "\xE6" => '&#1060;',
  154. "\xE7" => '&#1043;',
  155. "\xE8" => '&#1061;',
  156. "\xE9" => '&#1048;',
  157. "\xEA" => '&#1049;',
  158. "\xEB" => '&#1050;',
  159. "\xEC" => '&#1051;',
  160. "\xED" => '&#1052;',
  161. "\xEE" => '&#1053;',
  162. "\xEF" => '&#1054;',
  163. "\xF0" => '&#1055;',
  164. "\xF1" => '&#1071;',
  165. "\xF2" => '&#1056;',
  166. "\xF3" => '&#1057;',
  167. "\xF4" => '&#1058;',
  168. "\xF5" => '&#1059;',
  169. "\xF6" => '&#1046;',
  170. "\xF7" => '&#1042;',
  171. "\xF8" => '&#1068;',
  172. "\xF9" => '&#1067;',
  173. "\xFA" => '&#1047;',
  174. "\xFB" => '&#1064;',
  175. "\xFC" => '&#1069;',
  176. "\xFD" => '&#1065;',
  177. "\xFE" => '&#1063;',
  178. "\xFF" => '&#1066;'
  179. );
  180. $string = str_replace(array_keys($koi8r), array_values($koi8r), $string);
  181. return $string;
  182. }
  183. ?>