cp855.php 4.7 KB

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