koi8_r.php 5.4 KB

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