cp1255.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * decode/cp1255.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 cp1255 decoding function that is needed to read
  10. * cp1255 encoded mails in non-cp1255 locale.
  11. *
  12. * Original data taken from:
  13. * ftp://ftp.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1255.TXT
  14. *
  15. * Name: cp1255 to Unicode table
  16. * Unicode version: 2.0
  17. * Table version: 2.01
  18. * Table format: Format A
  19. * Date: 1/7/2000
  20. * Contact: cpxlate@microsoft.com
  21. * @package squirrelmail
  22. * @subpackage decode
  23. */
  24. /**
  25. * Decode cp1255-encoded string
  26. * @param string $string Encoded string
  27. * @return string $string decoded string
  28. */
  29. function charset_decode_cp1255 ($string) {
  30. global $default_charset;
  31. if (strtolower($default_charset) == 'windows-1255')
  32. return $string;
  33. /* Only do the slow convert if there are 8-bit characters */
  34. /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
  35. if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string) )
  36. return $string;
  37. $cp1255 = array(
  38. "\x80" => '&#8364;',
  39. "\x81" => '&#65533;',
  40. "\x82" => '&#8218;',
  41. "\x83" => '&#402;',
  42. "\x84" => '&#8222;',
  43. "\x85" => '&#8230;',
  44. "\x86" => '&#8224;',
  45. "\x87" => '&#8225;',
  46. "\x88" => '&#710;',
  47. "\x89" => '&#8240;',
  48. "\x8A" => '&#65533;',
  49. "\x8B" => '&#8249;',
  50. "\x8C" => '&#65533;',
  51. "\x8D" => '&#65533;',
  52. "\x8E" => '&#65533;',
  53. "\x8F" => '&#65533;',
  54. "\x90" => '&#65533;',
  55. "\x91" => '&#8216;',
  56. "\x92" => '&#8217;',
  57. "\x93" => '&#8220;',
  58. "\x94" => '&#8221;',
  59. "\x95" => '&#8226;',
  60. "\x96" => '&#8211;',
  61. "\x97" => '&#8212;',
  62. "\x98" => '&#732;',
  63. "\x99" => '&#8482;',
  64. "\x9A" => '&#65533;',
  65. "\x9B" => '&#8250;',
  66. "\x9C" => '&#65533;',
  67. "\x9D" => '&#65533;',
  68. "\x9E" => '&#65533;',
  69. "\x9F" => '&#65533;',
  70. "\xA0" => '&#160;',
  71. "\xA1" => '&#161;',
  72. "\xA2" => '&#162;',
  73. "\xA3" => '&#163;',
  74. "\xA4" => '&#8362;',
  75. "\xA5" => '&#165;',
  76. "\xA6" => '&#166;',
  77. "\xA7" => '&#167;',
  78. "\xA8" => '&#168;',
  79. "\xA9" => '&#169;',
  80. "\xAA" => '&#215;',
  81. "\xAB" => '&#171;',
  82. "\xAC" => '&#172;',
  83. "\xAD" => '&#173;',
  84. "\xAE" => '&#174;',
  85. "\xAF" => '&#175;',
  86. "\xB0" => '&#176;',
  87. "\xB1" => '&#177;',
  88. "\xB2" => '&#178;',
  89. "\xB3" => '&#179;',
  90. "\xB4" => '&#180;',
  91. "\xB5" => '&#181;',
  92. "\xB6" => '&#182;',
  93. "\xB7" => '&#183;',
  94. "\xB8" => '&#184;',
  95. "\xB9" => '&#185;',
  96. "\xBA" => '&#247;',
  97. "\xBB" => '&#187;',
  98. "\xBC" => '&#188;',
  99. "\xBD" => '&#189;',
  100. "\xBE" => '&#190;',
  101. "\xBF" => '&#191;',
  102. "\xC0" => '&#1456;',
  103. "\xC1" => '&#1457;',
  104. "\xC2" => '&#1458;',
  105. "\xC3" => '&#1459;',
  106. "\xC4" => '&#1460;',
  107. "\xC5" => '&#1461;',
  108. "\xC6" => '&#1462;',
  109. "\xC7" => '&#1463;',
  110. "\xC8" => '&#1464;',
  111. "\xC9" => '&#1465;',
  112. "\xCA" => '&#65533;',
  113. "\xCB" => '&#1467;',
  114. "\xCC" => '&#1468;',
  115. "\xCD" => '&#1469;',
  116. "\xCE" => '&#1470;',
  117. "\xCF" => '&#1471;',
  118. "\xD0" => '&#1472;',
  119. "\xD1" => '&#1473;',
  120. "\xD2" => '&#1474;',
  121. "\xD3" => '&#1475;',
  122. "\xD4" => '&#1520;',
  123. "\xD5" => '&#1521;',
  124. "\xD6" => '&#1522;',
  125. "\xD7" => '&#1523;',
  126. "\xD8" => '&#1524;',
  127. "\xD9" => '&#65533;',
  128. "\xDA" => '&#65533;',
  129. "\xDB" => '&#65533;',
  130. "\xDC" => '&#65533;',
  131. "\xDD" => '&#65533;',
  132. "\xDE" => '&#65533;',
  133. "\xDF" => '&#65533;',
  134. "\xE0" => '&#1488;',
  135. "\xE1" => '&#1489;',
  136. "\xE2" => '&#1490;',
  137. "\xE3" => '&#1491;',
  138. "\xE4" => '&#1492;',
  139. "\xE5" => '&#1493;',
  140. "\xE6" => '&#1494;',
  141. "\xE7" => '&#1495;',
  142. "\xE8" => '&#1496;',
  143. "\xE9" => '&#1497;',
  144. "\xEA" => '&#1498;',
  145. "\xEB" => '&#1499;',
  146. "\xEC" => '&#1500;',
  147. "\xED" => '&#1501;',
  148. "\xEE" => '&#1502;',
  149. "\xEF" => '&#1503;',
  150. "\xF0" => '&#1504;',
  151. "\xF1" => '&#1505;',
  152. "\xF2" => '&#1506;',
  153. "\xF3" => '&#1507;',
  154. "\xF4" => '&#1508;',
  155. "\xF5" => '&#1509;',
  156. "\xF6" => '&#1510;',
  157. "\xF7" => '&#1511;',
  158. "\xF8" => '&#1512;',
  159. "\xF9" => '&#1513;',
  160. "\xFA" => '&#1514;',
  161. "\xFB" => '&#65533;',
  162. "\xFC" => '&#65533;',
  163. "\xFD" => '&#8206;',
  164. "\xFE" => '&#8207;',
  165. "\xFF" => '&#65533;'
  166. );
  167. $string = str_replace(array_keys($cp1255), array_values($cp1255), $string);
  168. return $string;
  169. }
  170. ?>