cp1255.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * cp1255 encoding functions
  4. *
  5. * takes a string of unicode entities and converts it to a cp1255 encoded string
  6. * Unsupported characters are replaced with ?.
  7. *
  8. * @version $Id$
  9. * @copyright Copyright &copy; 2004-2005 The SquirrelMail Project Team
  10. * @package squirrelmail
  11. * @subpackage encode
  12. */
  13. /**
  14. * Converts string to cp1255
  15. * @param string $string text with numeric unicode entities
  16. * @return string cp1255 encoded text
  17. */
  18. function charset_encode_cp1255 ($string) {
  19. // don't run encoding function, if there is no encoded characters
  20. if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
  21. $string=preg_replace("/&#([0-9]+);/e","unicodetocp1255('\\1')",$string);
  22. // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetocp1255(hexdec('\\1'))",$string);
  23. return $string;
  24. }
  25. /**
  26. * Return cp1255 symbol when unicode character number is provided
  27. *
  28. * This function is used internally by charset_encode_cp1255
  29. * function. It might be unavailable to other SquirrelMail functions.
  30. * Don't use it or make sure, that functions/encode/cp1255.php is
  31. * included.
  32. *
  33. * @param int $var decimal unicode value
  34. * @return string cp1255 character
  35. */
  36. function unicodetocp1255($var) {
  37. $cp1255chars=array('160' => "\xA0",
  38. '161' => "\xA1",
  39. '162' => "\xA2",
  40. '163' => "\xA3",
  41. '165' => "\xA5",
  42. '166' => "\xA6",
  43. '167' => "\xA7",
  44. '168' => "\xA8",
  45. '169' => "\xA9",
  46. '171' => "\xAB",
  47. '172' => "\xAC",
  48. '173' => "\xAD",
  49. '174' => "\xAE",
  50. '175' => "\xAF",
  51. '176' => "\xB0",
  52. '177' => "\xB1",
  53. '178' => "\xB2",
  54. '179' => "\xB3",
  55. '180' => "\xB4",
  56. '181' => "\xB5",
  57. '182' => "\xB6",
  58. '183' => "\xB7",
  59. '184' => "\xB8",
  60. '185' => "\xB9",
  61. '187' => "\xBB",
  62. '188' => "\xBC",
  63. '189' => "\xBD",
  64. '190' => "\xBE",
  65. '191' => "\xBF",
  66. '215' => "\xAA",
  67. '247' => "\xBA",
  68. '402' => "\x83",
  69. '710' => "\x88",
  70. '732' => "\x98",
  71. '1456' => "\xC0",
  72. '1457' => "\xC1",
  73. '1458' => "\xC2",
  74. '1459' => "\xC3",
  75. '1460' => "\xC4",
  76. '1461' => "\xC5",
  77. '1462' => "\xC6",
  78. '1463' => "\xC7",
  79. '1464' => "\xC8",
  80. '1465' => "\xC9",
  81. '1467' => "\xCB",
  82. '1468' => "\xCC",
  83. '1469' => "\xCD",
  84. '1470' => "\xCE",
  85. '1471' => "\xCF",
  86. '1472' => "\xD0",
  87. '1473' => "\xD1",
  88. '1474' => "\xD2",
  89. '1475' => "\xD3",
  90. '1488' => "\xE0",
  91. '1489' => "\xE1",
  92. '1490' => "\xE2",
  93. '1491' => "\xE3",
  94. '1492' => "\xE4",
  95. '1493' => "\xE5",
  96. '1494' => "\xE6",
  97. '1495' => "\xE7",
  98. '1496' => "\xE8",
  99. '1497' => "\xE9",
  100. '1498' => "\xEA",
  101. '1499' => "\xEB",
  102. '1500' => "\xEC",
  103. '1501' => "\xED",
  104. '1502' => "\xEE",
  105. '1503' => "\xEF",
  106. '1504' => "\xF0",
  107. '1505' => "\xF1",
  108. '1506' => "\xF2",
  109. '1507' => "\xF3",
  110. '1508' => "\xF4",
  111. '1509' => "\xF5",
  112. '1510' => "\xF6",
  113. '1511' => "\xF7",
  114. '1512' => "\xF8",
  115. '1513' => "\xF9",
  116. '1514' => "\xFA",
  117. '1520' => "\xD4",
  118. '1521' => "\xD5",
  119. '1522' => "\xD6",
  120. '1523' => "\xD7",
  121. '1524' => "\xD8",
  122. '8206' => "\xFD",
  123. '8207' => "\xFE",
  124. '8211' => "\x96",
  125. '8212' => "\x97",
  126. '8216' => "\x91",
  127. '8217' => "\x92",
  128. '8218' => "\x82",
  129. '8220' => "\x93",
  130. '8221' => "\x94",
  131. '8222' => "\x84",
  132. '8224' => "\x86",
  133. '8225' => "\x87",
  134. '8226' => "\x95",
  135. '8230' => "\x85",
  136. '8240' => "\x89",
  137. '8249' => "\x8B",
  138. '8250' => "\x9B",
  139. '8362' => "\xA4",
  140. '8364' => "\x80",
  141. '8482' => "\x99");
  142. if (array_key_exists($var,$cp1255chars)) {
  143. $ret=$cp1255chars[$var];
  144. } else {
  145. $ret='?';
  146. }
  147. return $ret;
  148. }
  149. ?>