cp1257.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /*
  3. * decode/cp1257.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 cp1257 decoding function that is needed to read
  10. * cp1257 encoded mails in non-cp1257 locale.
  11. *
  12. * Original data taken from:
  13. * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1257.TXT
  14. *
  15. * Name: cp1257 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_cp1257 ($string) {
  24. global $default_charset;
  25. if (strtolower($default_charset) == 'windows-1257')
  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. $cp1257 = array(
  32. "\x80" => '&#8364;',
  33. "\x82" => '&#8218;',
  34. "\x84" => '&#8222;',
  35. "\x85" => '&#8230;',
  36. "\x86" => '&#8224;',
  37. "\x87" => '&#8225;',
  38. "\x89" => '&#8240;',
  39. "\x8B" => '&#8249;',
  40. "\x8D" => '&#168;',
  41. "\x8E" => '&#711;',
  42. "\x8F" => '&#184;',
  43. "\x91" => '&#8216;',
  44. "\x92" => '&#8217;',
  45. "\x93" => '&#8220;',
  46. "\x94" => '&#8221;',
  47. "\x95" => '&#8226;',
  48. "\x96" => '&#8211;',
  49. "\x97" => '&#8212;',
  50. "\x99" => '&#8482;',
  51. "\x9B" => '&#8250;',
  52. "\x9D" => '&#175;',
  53. "\x9E" => '&#731;',
  54. "\xA0" => '&#160;',
  55. "\xA2" => '&#162;',
  56. "\xA3" => '&#163;',
  57. "\xA4" => '&#164;',
  58. "\xA6" => '&#166;',
  59. "\xA7" => '&#167;',
  60. "\xA8" => '&#216;',
  61. "\xA9" => '&#169;',
  62. "\xAA" => '&#342;',
  63. "\xAB" => '&#171;',
  64. "\xAC" => '&#172;',
  65. "\xAD" => '&#173;',
  66. "\xAE" => '&#174;',
  67. "\xAF" => '&#198;',
  68. "\xB0" => '&#176;',
  69. "\xB1" => '&#177;',
  70. "\xB2" => '&#178;',
  71. "\xB3" => '&#179;',
  72. "\xB4" => '&#180;',
  73. "\xB5" => '&#181;',
  74. "\xB6" => '&#182;',
  75. "\xB7" => '&#183;',
  76. "\xB8" => '&#248;',
  77. "\xB9" => '&#185;',
  78. "\xBA" => '&#343;',
  79. "\xBB" => '&#187;',
  80. "\xBC" => '&#188;',
  81. "\xBD" => '&#189;',
  82. "\xBE" => '&#190;',
  83. "\xBF" => '&#230;',
  84. "\xC0" => '&#260;',
  85. "\xC1" => '&#302;',
  86. "\xC2" => '&#256;',
  87. "\xC3" => '&#262;',
  88. "\xC4" => '&#196;',
  89. "\xC5" => '&#197;',
  90. "\xC6" => '&#280;',
  91. "\xC7" => '&#274;',
  92. "\xC8" => '&#268;',
  93. "\xC9" => '&#201;',
  94. "\xCA" => '&#377;',
  95. "\xCB" => '&#278;',
  96. "\xCC" => '&#290;',
  97. "\xCD" => '&#310;',
  98. "\xCE" => '&#298;',
  99. "\xCF" => '&#315;',
  100. "\xD0" => '&#352;',
  101. "\xD1" => '&#323;',
  102. "\xD2" => '&#325;',
  103. "\xD3" => '&#211;',
  104. "\xD4" => '&#332;',
  105. "\xD5" => '&#213;',
  106. "\xD6" => '&#214;',
  107. "\xD7" => '&#215;',
  108. "\xD8" => '&#370;',
  109. "\xD9" => '&#321;',
  110. "\xDA" => '&#346;',
  111. "\xDB" => '&#362;',
  112. "\xDC" => '&#220;',
  113. "\xDD" => '&#379;',
  114. "\xDE" => '&#381;',
  115. "\xDF" => '&#223;',
  116. "\xE0" => '&#261;',
  117. "\xE1" => '&#303;',
  118. "\xE2" => '&#257;',
  119. "\xE3" => '&#263;',
  120. "\xE4" => '&#228;',
  121. "\xE5" => '&#229;',
  122. "\xE6" => '&#281;',
  123. "\xE7" => '&#275;',
  124. "\xE8" => '&#269;',
  125. "\xE9" => '&#233;',
  126. "\xEA" => '&#378;',
  127. "\xEB" => '&#279;',
  128. "\xEC" => '&#291;',
  129. "\xED" => '&#311;',
  130. "\xEE" => '&#299;',
  131. "\xEF" => '&#316;',
  132. "\xF0" => '&#353;',
  133. "\xF1" => '&#324;',
  134. "\xF2" => '&#326;',
  135. "\xF3" => '&#243;',
  136. "\xF4" => '&#333;',
  137. "\xF5" => '&#245;',
  138. "\xF6" => '&#246;',
  139. "\xF7" => '&#247;',
  140. "\xF8" => '&#371;',
  141. "\xF9" => '&#322;',
  142. "\xFA" => '&#347;',
  143. "\xFB" => '&#363;',
  144. "\xFC" => '&#252;',
  145. "\xFD" => '&#380;',
  146. "\xFE" => '&#382;',
  147. "\xFF" => '&#729;'
  148. );
  149. $string = str_replace(array_keys($cp1257), array_values($cp1257), $string);
  150. return $string;
  151. }
  152. ?>