cp855.php 4.1 KB

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