cp866.php 4.1 KB

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