cp1251.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * decode/cp1251.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 cp1251 decoding function that is needed to read
  9. * cp1251 encoded mails in non-cp1251 locale.
  10. *
  11. * Original data taken from:
  12. * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1250.TXT
  13. *
  14. * Name: cp1251 to Unicode table
  15. * Unicode version: 2.0
  16. * Table version: 2.01
  17. * Table format: Format A
  18. * Date: 04/15/98
  19. * Contact: cpxlate@microsoft.com
  20. *
  21. * @version $Id$
  22. * @package squirrelmail
  23. * @subpackage decode
  24. */
  25. /**
  26. * Decode cp1251-encoded string
  27. * @param string $string Encoded string
  28. * @return string $string Decoded string
  29. */
  30. function charset_decode_cp1251 ($string) {
  31. global $default_charset;
  32. if (strtolower($default_charset) == 'windows-1251')
  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. $cp1251 = array(
  39. "\x80" => '&#1026;',
  40. "\x81" => '&#1027;',
  41. "\x82" => '&#8218;',
  42. "\x83" => '&#1107;',
  43. "\x84" => '&#8222;',
  44. "\x85" => '&#8230;',
  45. "\x86" => '&#8224;',
  46. "\x87" => '&#8225;',
  47. "\x88" => '&#8364;',
  48. "\x89" => '&#8240;',
  49. "\x8A" => '&#1033;',
  50. "\x8B" => '&#8249;',
  51. "\x8C" => '&#1034;',
  52. "\x8D" => '&#1036;',
  53. "\x8E" => '&#1035;',
  54. "\x8F" => '&#1039;',
  55. "\x90" => '&#1106;',
  56. "\x91" => '&#8216;',
  57. "\x92" => '&#8217;',
  58. "\x93" => '&#8220;',
  59. "\x94" => '&#8221;',
  60. "\x95" => '&#8226;',
  61. "\x96" => '&#8211;',
  62. "\x97" => '&#8212;',
  63. "\x98" => '&#65533;',
  64. "\x99" => '&#8482;',
  65. "\x9A" => '&#1113;',
  66. "\x9B" => '&#8250;',
  67. "\x9C" => '&#1114;',
  68. "\x9D" => '&#1116;',
  69. "\x9E" => '&#1115;',
  70. "\x9F" => '&#1119;',
  71. "\xA0" => '&#160;',
  72. "\xA1" => '&#1038;',
  73. "\xA2" => '&#1118;',
  74. "\xA3" => '&#1032;',
  75. "\xA4" => '&#164;',
  76. "\xA5" => '&#1168;',
  77. "\xA6" => '&#166;',
  78. "\xA7" => '&#167;',
  79. "\xA8" => '&#1025;',
  80. "\xA9" => '&#169;',
  81. "\xAA" => '&#1028;',
  82. "\xAB" => '&#171;',
  83. "\xAC" => '&#172;',
  84. "\xAD" => '&#173;',
  85. "\xAE" => '&#174;',
  86. "\xAF" => '&#1031;',
  87. "\xB0" => '&#176;',
  88. "\xB1" => '&#177;',
  89. "\xB2" => '&#1030;',
  90. "\xB3" => '&#1110;',
  91. "\xB4" => '&#1169;',
  92. "\xB5" => '&#181;',
  93. "\xB6" => '&#182;',
  94. "\xB7" => '&#183;',
  95. "\xB8" => '&#1105;',
  96. "\xB9" => '&#8470;',
  97. "\xBA" => '&#1108;',
  98. "\xBB" => '&#187;',
  99. "\xBC" => '&#1112;',
  100. "\xBD" => '&#1029;',
  101. "\xBE" => '&#1109;',
  102. "\xBF" => '&#1111;',
  103. "\xC0" => '&#1040;',
  104. "\xC1" => '&#1041;',
  105. "\xC2" => '&#1042;',
  106. "\xC3" => '&#1043;',
  107. "\xC4" => '&#1044;',
  108. "\xC5" => '&#1045;',
  109. "\xC6" => '&#1046;',
  110. "\xC7" => '&#1047;',
  111. "\xC8" => '&#1048;',
  112. "\xC9" => '&#1049;',
  113. "\xCA" => '&#1050;',
  114. "\xCB" => '&#1051;',
  115. "\xCC" => '&#1052;',
  116. "\xCD" => '&#1053;',
  117. "\xCE" => '&#1054;',
  118. "\xCF" => '&#1055;',
  119. "\xD0" => '&#1056;',
  120. "\xD1" => '&#1057;',
  121. "\xD2" => '&#1058;',
  122. "\xD3" => '&#1059;',
  123. "\xD4" => '&#1060;',
  124. "\xD5" => '&#1061;',
  125. "\xD6" => '&#1062;',
  126. "\xD7" => '&#1063;',
  127. "\xD8" => '&#1064;',
  128. "\xD9" => '&#1065;',
  129. "\xDA" => '&#1066;',
  130. "\xDB" => '&#1067;',
  131. "\xDC" => '&#1068;',
  132. "\xDD" => '&#1069;',
  133. "\xDE" => '&#1070;',
  134. "\xDF" => '&#1071;',
  135. "\xE0" => '&#1072;',
  136. "\xE1" => '&#1073;',
  137. "\xE2" => '&#1074;',
  138. "\xE3" => '&#1075;',
  139. "\xE4" => '&#1076;',
  140. "\xE5" => '&#1077;',
  141. "\xE6" => '&#1078;',
  142. "\xE7" => '&#1079;',
  143. "\xE8" => '&#1080;',
  144. "\xE9" => '&#1081;',
  145. "\xEA" => '&#1082;',
  146. "\xEB" => '&#1083;',
  147. "\xEC" => '&#1084;',
  148. "\xED" => '&#1085;',
  149. "\xEE" => '&#1086;',
  150. "\xEF" => '&#1087;',
  151. "\xF0" => '&#1088;',
  152. "\xF1" => '&#1089;',
  153. "\xF2" => '&#1090;',
  154. "\xF3" => '&#1091;',
  155. "\xF4" => '&#1092;',
  156. "\xF5" => '&#1093;',
  157. "\xF6" => '&#1094;',
  158. "\xF7" => '&#1095;',
  159. "\xF8" => '&#1096;',
  160. "\xF9" => '&#1097;',
  161. "\xFA" => '&#1098;',
  162. "\xFB" => '&#1099;',
  163. "\xFC" => '&#1100;',
  164. "\xFD" => '&#1101;',
  165. "\xFE" => '&#1102;',
  166. "\xFF" => '&#1103;'
  167. );
  168. $string = str_replace(array_keys($cp1251), array_values($cp1251), $string);
  169. return $string;
  170. }
  171. ?>