cp855.php 3.9 KB

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