/libs/functions/decode/cp1257.php

https://github.com/dslfaithdev/soEmail · PHP · 159 lines · 125 code · 6 blank · 28 comment · 1 complexity · 26aed57cac06864f538caddfc23c6f98 MD5 · raw file

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