cp1256.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /**
  3. * cp1256 encoding functions
  4. *
  5. * takes a string of unicode entities and converts it to a cp1256 encoded string
  6. * Unsupported characters are replaced with ?.
  7. *
  8. * @copyright 2004-2025 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id$
  11. * @package squirrelmail
  12. * @subpackage encode
  13. */
  14. /**
  15. * Converts string to cp1256
  16. * @param string $string text with numeric unicode entities
  17. * @return string cp1256 encoded text
  18. */
  19. function charset_encode_cp1256 ($string) {
  20. // don't run encoding function, if there is no encoded characters
  21. if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
  22. $string=preg_replace_callback("/&#([0-9]+);/",'unicodetocp1256',$string);
  23. return $string;
  24. }
  25. /**
  26. * Return cp1256 symbol when unicode character number is provided
  27. *
  28. * This function is used internally by charset_encode_cp1256
  29. * function. It might be unavailable to other SquirrelMail functions.
  30. * Don't use it or make sure, that functions/encode/cp1256.php is
  31. * included.
  32. *
  33. * @param array $matches array with first element a decimal unicode value
  34. * @return string cp1256 character
  35. */
  36. function unicodetocp1256($matches) {
  37. $var = $matches[1];
  38. $cp1256chars=array('160' => "\xA0",
  39. '162' => "\xA2",
  40. '163' => "\xA3",
  41. '164' => "\xA4",
  42. '165' => "\xA5",
  43. '166' => "\xA6",
  44. '167' => "\xA7",
  45. '168' => "\xA8",
  46. '169' => "\xA9",
  47. '171' => "\xAB",
  48. '172' => "\xAC",
  49. '173' => "\xAD",
  50. '174' => "\xAE",
  51. '175' => "\xAF",
  52. '176' => "\xB0",
  53. '177' => "\xB1",
  54. '178' => "\xB2",
  55. '179' => "\xB3",
  56. '180' => "\xB4",
  57. '181' => "\xB5",
  58. '182' => "\xB6",
  59. '183' => "\xB7",
  60. '184' => "\xB8",
  61. '185' => "\xB9",
  62. '187' => "\xBB",
  63. '188' => "\xBC",
  64. '189' => "\xBD",
  65. '190' => "\xBE",
  66. '215' => "\xD7",
  67. '224' => "\xE0",
  68. '226' => "\xE2",
  69. '231' => "\xE7",
  70. '232' => "\xE8",
  71. '233' => "\xE9",
  72. '234' => "\xEA",
  73. '235' => "\xEB",
  74. '238' => "\xEE",
  75. '239' => "\xEF",
  76. '244' => "\xF4",
  77. '247' => "\xF7",
  78. '249' => "\xF9",
  79. '251' => "\xFB",
  80. '252' => "\xFC",
  81. '338' => "\x8C",
  82. '339' => "\x9C",
  83. '402' => "\x83",
  84. '710' => "\x88",
  85. '1548' => "\xA1",
  86. '1563' => "\xBA",
  87. '1567' => "\xBF",
  88. '1569' => "\xC1",
  89. '1570' => "\xC2",
  90. '1571' => "\xC3",
  91. '1572' => "\xC4",
  92. '1573' => "\xC5",
  93. '1574' => "\xC6",
  94. '1575' => "\xC7",
  95. '1576' => "\xC8",
  96. '1577' => "\xC9",
  97. '1578' => "\xCA",
  98. '1579' => "\xCB",
  99. '1580' => "\xCC",
  100. '1581' => "\xCD",
  101. '1582' => "\xCE",
  102. '1583' => "\xCF",
  103. '1584' => "\xD0",
  104. '1585' => "\xD1",
  105. '1586' => "\xD2",
  106. '1587' => "\xD3",
  107. '1588' => "\xD4",
  108. '1589' => "\xD5",
  109. '1590' => "\xD6",
  110. '1591' => "\xD8",
  111. '1592' => "\xD9",
  112. '1593' => "\xDA",
  113. '1594' => "\xDB",
  114. '1600' => "\xDC",
  115. '1601' => "\xDD",
  116. '1602' => "\xDE",
  117. '1603' => "\xDF",
  118. '1604' => "\xE1",
  119. '1605' => "\xE3",
  120. '1606' => "\xE4",
  121. '1607' => "\xE5",
  122. '1608' => "\xE6",
  123. '1609' => "\xEC",
  124. '1610' => "\xED",
  125. '1611' => "\xF0",
  126. '1612' => "\xF1",
  127. '1613' => "\xF2",
  128. '1614' => "\xF3",
  129. '1615' => "\xF5",
  130. '1616' => "\xF6",
  131. '1617' => "\xF8",
  132. '1618' => "\xFA",
  133. '1657' => "\x8A",
  134. '1662' => "\x81",
  135. '1670' => "\x8D",
  136. '1672' => "\x8F",
  137. '1681' => "\x9A",
  138. '1688' => "\x8E",
  139. '1705' => "\x98",
  140. '1711' => "\x90",
  141. '1722' => "\x9F",
  142. '1726' => "\xAA",
  143. '1729' => "\xC0",
  144. '1746' => "\xFF",
  145. '8204' => "\x9D",
  146. '8205' => "\x9E",
  147. '8206' => "\xFD",
  148. '8207' => "\xFE",
  149. '8211' => "\x96",
  150. '8212' => "\x97",
  151. '8216' => "\x91",
  152. '8217' => "\x92",
  153. '8218' => "\x82",
  154. '8220' => "\x93",
  155. '8221' => "\x94",
  156. '8222' => "\x84",
  157. '8224' => "\x86",
  158. '8225' => "\x87",
  159. '8226' => "\x95",
  160. '8230' => "\x85",
  161. '8240' => "\x89",
  162. '8249' => "\x8B",
  163. '8250' => "\x9B",
  164. '8364' => "\x80",
  165. '8482' => "\x99");
  166. if (array_key_exists($var,$cp1256chars)) {
  167. $ret=$cp1256chars[$var];
  168. } else {
  169. $ret='?';
  170. }
  171. return $ret;
  172. }