cp866.php 4.8 KB

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