cp1251.php 3.8 KB

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