cp10017.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /*
  3. * decode/cp10017.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 cp10017 (MacUkrainian) decoding function that
  10. * is needed to read cp10017 encoded mails in non-cp10017 locale.
  11. *
  12. * Apple states [2] that x-mac-ukrainian differs from x-mac-cyrillic [1]
  13. * only in two places. According to [3] these symbols are:
  14. * 0x92 - U+1168 - CYRILLIC CAPITAL LETTER GHE WITH UPTURN
  15. * 0xD6 - U+1169 - CYRILLIC SMALL LETTER GHE WITH UPTURN
  16. *
  17. * References:
  18. * 1. ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/MAC/CYRILLIC.TXT
  19. * 2. http://developer.apple.com/documentation/macos8/TextIntlSvcs/TextEncodingConversionManager/TEC1.5/TEC.b0.html
  20. * 3. http://shlimazl.nm.ru/rus/cptable.htm (page in Russian)
  21. */
  22. function charset_decode_cp10017 ($string) {
  23. global $default_charset;
  24. if (strtolower($default_charset) == 'x-mac-ukrainian')
  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. $cp10017 = array(
  31. "\x80" => '&#1040;',
  32. "\x81" => '&#1041;',
  33. "\x82" => '&#1042;',
  34. "\x83" => '&#1043;',
  35. "\x84" => '&#1044;',
  36. "\x85" => '&#1045;',
  37. "\x86" => '&#1046;',
  38. "\x87" => '&#1047;',
  39. "\x88" => '&#1048;',
  40. "\x89" => '&#1049;',
  41. "\x8A" => '&#1050;',
  42. "\x8B" => '&#1051;',
  43. "\x8C" => '&#1052;',
  44. "\x8D" => '&#1053;',
  45. "\x8E" => '&#1054;',
  46. "\x8F" => '&#1055;',
  47. "\x90" => '&#1056;',
  48. "\x91" => '&#1057;',
  49. "\x92" => '&#1168;',
  50. "\x93" => '&#1059;',
  51. "\x94" => '&#1060;',
  52. "\x95" => '&#1061;',
  53. "\x96" => '&#1062;',
  54. "\x97" => '&#1063;',
  55. "\x98" => '&#1064;',
  56. "\x99" => '&#1065;',
  57. "\x9A" => '&#1066;',
  58. "\x9B" => '&#1067;',
  59. "\x9C" => '&#1068;',
  60. "\x9D" => '&#1069;',
  61. "\x9E" => '&#1070;',
  62. "\x9F" => '&#1071;',
  63. "\xA0" => '&#8224;',
  64. "\xA1" => '&#176;',
  65. "\xA2" => '&#162;',
  66. "\xA3" => '&#163;',
  67. "\xA4" => '&#167;',
  68. "\xA5" => '&#8226;',
  69. "\xA6" => '&#182;',
  70. "\xA7" => '&#1030;',
  71. "\xA8" => '&#174;',
  72. "\xA9" => '&#169;',
  73. "\xAA" => '&#8482;',
  74. "\xAB" => '&#1026;',
  75. "\xAC" => '&#1106;',
  76. "\xAD" => '&#8800;',
  77. "\xAE" => '&#1027;',
  78. "\xAF" => '&#1107;',
  79. "\xB0" => '&#8734;',
  80. "\xB1" => '&#177;',
  81. "\xB2" => '&#8804;',
  82. "\xB3" => '&#8805;',
  83. "\xB4" => '&#1110;',
  84. "\xB5" => '&#181;',
  85. "\xB6" => '&#8706;',
  86. "\xB7" => '&#1032;',
  87. "\xB8" => '&#1028;',
  88. "\xB9" => '&#1108;',
  89. "\xBA" => '&#1031;',
  90. "\xBB" => '&#1111;',
  91. "\xBC" => '&#1033;',
  92. "\xBD" => '&#1113;',
  93. "\xBE" => '&#1034;',
  94. "\xBF" => '&#1114;',
  95. "\xC0" => '&#1112;',
  96. "\xC1" => '&#1029;',
  97. "\xC2" => '&#172;',
  98. "\xC3" => '&#8730;',
  99. "\xC4" => '&#402;',
  100. "\xC5" => '&#8776;',
  101. "\xC6" => '&#8710;',
  102. "\xC7" => '&#171;',
  103. "\xC8" => '&#187;',
  104. "\xC9" => '&#8230;',
  105. "\xCA" => '&#160;',
  106. "\xCB" => '&#1035;',
  107. "\xCC" => '&#1115;',
  108. "\xCD" => '&#1036;',
  109. "\xCE" => '&#1116;',
  110. "\xCF" => '&#1109;',
  111. "\xD0" => '&#8211;',
  112. "\xD1" => '&#8212;',
  113. "\xD2" => '&#8220;',
  114. "\xD3" => '&#8221;',
  115. "\xD4" => '&#8216;',
  116. "\xD5" => '&#8217;',
  117. "\xD6" => '&#1169;',
  118. "\xD7" => '&#8222;',
  119. "\xD8" => '&#1038;',
  120. "\xD9" => '&#1118;',
  121. "\xDA" => '&#1039;',
  122. "\xDB" => '&#1119;',
  123. "\xDC" => '&#8470;',
  124. "\xDD" => '&#1025;',
  125. "\xDE" => '&#1105;',
  126. "\xDF" => '&#1103;',
  127. "\xE0" => '&#1072;',
  128. "\xE1" => '&#1073;',
  129. "\xE2" => '&#1074;',
  130. "\xE3" => '&#1075;',
  131. "\xE4" => '&#1076;',
  132. "\xE5" => '&#1077;',
  133. "\xE6" => '&#1078;',
  134. "\xE7" => '&#1079;',
  135. "\xE8" => '&#1080;',
  136. "\xE9" => '&#1081;',
  137. "\xEA" => '&#1082;',
  138. "\xEB" => '&#1083;',
  139. "\xEC" => '&#1084;',
  140. "\xED" => '&#1085;',
  141. "\xEE" => '&#1086;',
  142. "\xEF" => '&#1087;',
  143. "\xF0" => '&#1088;',
  144. "\xF1" => '&#1089;',
  145. "\xF2" => '&#1090;',
  146. "\xF3" => '&#1091;',
  147. "\xF4" => '&#1092;',
  148. "\xF5" => '&#1093;',
  149. "\xF6" => '&#1094;',
  150. "\xF7" => '&#1095;',
  151. "\xF8" => '&#1096;',
  152. "\xF9" => '&#1097;',
  153. "\xFA" => '&#1098;',
  154. "\xFB" => '&#1099;',
  155. "\xFC" => '&#1100;',
  156. "\xFD" => '&#1101;',
  157. "\xFE" => '&#1102;',
  158. "\xFF" => '&#164;'
  159. );
  160. $string = str_replace(array_keys($cp10017), array_values($cp10017), $string);
  161. return $string;
  162. }
  163. ?>