cp1257.php 3.7 KB

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