iso_8859_7.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * iso-8859-7 encoding functions
  4. *
  5. * takes a string of unicode entities and converts it to a iso-8859-7 encoded string
  6. * Unsupported characters are replaced with ?.
  7. *
  8. * @copyright &copy; 2004-2006 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 iso-8859-7
  16. * @param string $string text with numeric unicode entities
  17. * @return string iso-8859-7 encoded text
  18. */
  19. function charset_encode_iso_8859_7 ($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("/&#([0-9]+);/e","unicodetoiso88597('\\1')",$string);
  23. // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88597(hexdec('\\1'))",$string);
  24. return $string;
  25. }
  26. /**
  27. * Return iso-8859-7 symbol when unicode character number is provided
  28. *
  29. * This function is used internally by charset_encode_iso_8859_7
  30. * function. It might be unavailable to other SquirrelMail functions.
  31. * Don't use it or make sure, that functions/encode/iso_8859_7.php is
  32. * included.
  33. *
  34. * @param int $var decimal unicode value
  35. * @return string iso-8859-7 character
  36. */
  37. function unicodetoiso88597($var) {
  38. $iso88597chars=array('160' => "\xA0",
  39. '163' => "\xA3",
  40. '166' => "\xA6",
  41. '167' => "\xA7",
  42. '168' => "\xA8",
  43. '169' => "\xA9",
  44. '171' => "\xAB",
  45. '172' => "\xAC",
  46. '173' => "\xAD",
  47. '176' => "\xB0",
  48. '177' => "\xB1",
  49. '178' => "\xB2",
  50. '179' => "\xB3",
  51. '183' => "\xB7",
  52. '187' => "\xBB",
  53. '189' => "\xBD",
  54. '900' => "\xB4",
  55. '901' => "\xB5",
  56. '902' => "\xB6",
  57. '904' => "\xB8",
  58. '905' => "\xB9",
  59. '906' => "\xBA",
  60. '908' => "\xBC",
  61. '910' => "\xBE",
  62. '911' => "\xBF",
  63. '912' => "\xC0",
  64. '913' => "\xC1",
  65. '914' => "\xC2",
  66. '915' => "\xC3",
  67. '916' => "\xC4",
  68. '917' => "\xC5",
  69. '918' => "\xC6",
  70. '919' => "\xC7",
  71. '920' => "\xC8",
  72. '921' => "\xC9",
  73. '922' => "\xCA",
  74. '923' => "\xCB",
  75. '924' => "\xCC",
  76. '925' => "\xCD",
  77. '926' => "\xCE",
  78. '927' => "\xCF",
  79. '928' => "\xD0",
  80. '929' => "\xD1",
  81. '931' => "\xD3",
  82. '932' => "\xD4",
  83. '933' => "\xD5",
  84. '934' => "\xD6",
  85. '935' => "\xD7",
  86. '936' => "\xD8",
  87. '937' => "\xD9",
  88. '938' => "\xDA",
  89. '939' => "\xDB",
  90. '940' => "\xDC",
  91. '941' => "\xDD",
  92. '942' => "\xDE",
  93. '943' => "\xDF",
  94. '944' => "\xE0",
  95. '945' => "\xE1",
  96. '946' => "\xE2",
  97. '947' => "\xE3",
  98. '948' => "\xE4",
  99. '949' => "\xE5",
  100. '950' => "\xE6",
  101. '951' => "\xE7",
  102. '952' => "\xE8",
  103. '953' => "\xE9",
  104. '954' => "\xEA",
  105. '955' => "\xEB",
  106. '956' => "\xEC",
  107. '957' => "\xED",
  108. '958' => "\xEE",
  109. '959' => "\xEF",
  110. '960' => "\xF0",
  111. '961' => "\xF1",
  112. '962' => "\xF2",
  113. '963' => "\xF3",
  114. '964' => "\xF4",
  115. '965' => "\xF5",
  116. '966' => "\xF6",
  117. '967' => "\xF7",
  118. '968' => "\xF8",
  119. '969' => "\xF9",
  120. '970' => "\xFA",
  121. '971' => "\xFB",
  122. '972' => "\xFC",
  123. '973' => "\xFD",
  124. '974' => "\xFE",
  125. '8213' => "\xAF",
  126. '8216' => "\xA1",
  127. '8217' => "\xA2");
  128. if (array_key_exists($var,$iso88597chars)) {
  129. $ret=$iso88597chars[$var];
  130. } else {
  131. $ret='?';
  132. }
  133. return $ret;
  134. }