cp866.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * decode/cp866.php
  4. * $Id$
  5. *
  6. * Copyright (c) 2003-2004 The SquirrelMail Project Team
  7. * Licensed under the GNU GPL. For full terms see the file COPYING.
  8. *
  9. * This file contains cp866 decoding function that is needed to read
  10. * cp866 encoded mails in non-cp866 locale.
  11. *
  12. * Original data taken from:
  13. * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/
  14. Name: cp866_DOSCyrillicRussian to Unicode table
  15. Unicode version: 2.0
  16. Table version: 2.00
  17. Table format: Format A
  18. Date: 04/24/96
  19. Authors: Lori Brownell <loribr@microsoft.com>
  20. K.D. Chang <a-kchang@microsoft.com>
  21. The entries are in cp866_DOSCyrillicRussian order
  22. * @package squirrelmail
  23. * @subpackage decode
  24. */
  25. /**
  26. * Decode a cp866-encoded string
  27. * @param string $string Encoded string
  28. * @return string $string Decoded string
  29. */
  30. function charset_decode_cp866 ($string) {
  31. global $default_charset;
  32. if (strtolower($default_charset) == 'ibm866')
  33. return $string;
  34. /* Only do the slow convert if there are 8-bit characters */
  35. /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
  36. if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
  37. return $string;
  38. $cp866 = array(
  39. "\x80" => '&#1040;',
  40. "\x81" => '&#1041;',
  41. "\x82" => '&#1042;',
  42. "\x83" => '&#1043;',
  43. "\x84" => '&#1044;',
  44. "\x85" => '&#1045;',
  45. "\x86" => '&#1046;',
  46. "\x87" => '&#1047;',
  47. "\x88" => '&#1048;',
  48. "\x89" => '&#1049;',
  49. "\x8a" => '&#1050;',
  50. "\x8b" => '&#1051;',
  51. "\x8c" => '&#1052;',
  52. "\x8d" => '&#1053;',
  53. "\x8e" => '&#1054;',
  54. "\x8f" => '&#1055;',
  55. "\x90" => '&#1056;',
  56. "\x91" => '&#1057;',
  57. "\x92" => '&#1058;',
  58. "\x93" => '&#1059;',
  59. "\x94" => '&#1060;',
  60. "\x95" => '&#1061;',
  61. "\x96" => '&#1062;',
  62. "\x97" => '&#1063;',
  63. "\x98" => '&#1064;',
  64. "\x99" => '&#1065;',
  65. "\x9a" => '&#1066;',
  66. "\x9b" => '&#1067;',
  67. "\x9c" => '&#1068;',
  68. "\x9d" => '&#1069;',
  69. "\x9e" => '&#1070;',
  70. "\x9f" => '&#1071;',
  71. "\xa0" => '&#1072;',
  72. "\xa1" => '&#1073;',
  73. "\xa2" => '&#1074;',
  74. "\xa3" => '&#1075;',
  75. "\xa4" => '&#1076;',
  76. "\xa5" => '&#1077;',
  77. "\xa6" => '&#1078;',
  78. "\xa7" => '&#1079;',
  79. "\xa8" => '&#1080;',
  80. "\xa9" => '&#1081;',
  81. "\xaa" => '&#1082;',
  82. "\xab" => '&#1083;',
  83. "\xac" => '&#1084;',
  84. "\xad" => '&#1085;',
  85. "\xae" => '&#1086;',
  86. "\xaf" => '&#1087;',
  87. "\xb0" => '&#9617;',
  88. "\xb1" => '&#9618;',
  89. "\xb2" => '&#9619;',
  90. "\xb3" => '&#9474;',
  91. "\xb4" => '&#9508;',
  92. "\xb5" => '&#9569;',
  93. "\xb6" => '&#9570;',
  94. "\xb7" => '&#9558;',
  95. "\xb8" => '&#9557;',
  96. "\xb9" => '&#9571;',
  97. "\xba" => '&#9553;',
  98. "\xbb" => '&#9559;',
  99. "\xbc" => '&#9565;',
  100. "\xbd" => '&#9564;',
  101. "\xbe" => '&#9563;',
  102. "\xbf" => '&#9488;',
  103. "\xc0" => '&#9492;',
  104. "\xc1" => '&#9524;',
  105. "\xc2" => '&#9516;',
  106. "\xc3" => '&#9500;',
  107. "\xc4" => '&#9472;',
  108. "\xc5" => '&#9532;',
  109. "\xc6" => '&#9566;',
  110. "\xc7" => '&#9567;',
  111. "\xc8" => '&#9562;',
  112. "\xc9" => '&#9556;',
  113. "\xca" => '&#9577;',
  114. "\xcb" => '&#9574;',
  115. "\xcc" => '&#9568;',
  116. "\xcd" => '&#9552;',
  117. "\xce" => '&#9580;',
  118. "\xcf" => '&#9575;',
  119. "\xd0" => '&#9576;',
  120. "\xd1" => '&#9572;',
  121. "\xd2" => '&#9573;',
  122. "\xd3" => '&#9561;',
  123. "\xd4" => '&#9560;',
  124. "\xd5" => '&#9554;',
  125. "\xd6" => '&#9555;',
  126. "\xd7" => '&#9579;',
  127. "\xd8" => '&#9578;',
  128. "\xd9" => '&#9496;',
  129. "\xda" => '&#9484;',
  130. "\xdb" => '&#9608;',
  131. "\xdc" => '&#9604;',
  132. "\xdd" => '&#9612;',
  133. "\xde" => '&#9616;',
  134. "\xdf" => '&#9600;',
  135. "\xe0" => '&#1088;',
  136. "\xe1" => '&#1089;',
  137. "\xe2" => '&#1090;',
  138. "\xe3" => '&#1091;',
  139. "\xe4" => '&#1092;',
  140. "\xe5" => '&#1093;',
  141. "\xe6" => '&#1094;',
  142. "\xe7" => '&#1095;',
  143. "\xe8" => '&#1096;',
  144. "\xe9" => '&#1097;',
  145. "\xea" => '&#1098;',
  146. "\xeb" => '&#1099;',
  147. "\xec" => '&#1100;',
  148. "\xed" => '&#1101;',
  149. "\xee" => '&#1102;',
  150. "\xef" => '&#1103;',
  151. "\xf0" => '&#1025;',
  152. "\xf1" => '&#1105;',
  153. "\xf2" => '&#1028;',
  154. "\xf3" => '&#1108;',
  155. "\xf4" => '&#1031;',
  156. "\xf5" => '&#1111;',
  157. "\xf6" => '&#1038;',
  158. "\xf7" => '&#1118;',
  159. "\xf8" => '&#176;',
  160. "\xf9" => '&#8729;',
  161. "\xfa" => '&#183;',
  162. "\xfb" => '&#8730;',
  163. "\xfc" => '&#8470;',
  164. "\xfd" => '&#164;',
  165. "\xfe" => '&#9632;',
  166. "\xff" => '&#160;'
  167. );
  168. $string = str_replace(array_keys($cp866), array_values($cp866), $string);
  169. return $string;
  170. }