cp855.php 4.1 KB

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