iso_8859_2.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * iso-8859-2 encoding functions
  4. *
  5. * takes a string of unicode entities and converts it to a iso-8859-2 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-2
  16. * @param string $string text with numeric unicode entities
  17. * @return string iso-8859-2 encoded text
  18. */
  19. function charset_encode_iso_8859_2 ($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","unicodetoiso88592('\\1')",$string);
  23. // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88592(hexdec('\\1'))",$string);
  24. return $string;
  25. }
  26. /**
  27. * Return iso-8859-2 symbol when unicode character number is provided
  28. *
  29. * This function is used internally by charset_encode_iso_8859_2
  30. * function. It might be unavailable to other SquirrelMail functions.
  31. * Don't use it or make sure, that functions/encode/iso_8859_2.php is
  32. * included.
  33. *
  34. * @param int $var decimal unicode value
  35. * @return string iso-8859-2 character
  36. */
  37. function unicodetoiso88592($var) {
  38. $iso88592chars=array('160' => "\xA0",
  39. '164' => "\xA4",
  40. '167' => "\xA7",
  41. '168' => "\xA8",
  42. '173' => "\xAD",
  43. '176' => "\xB0",
  44. '180' => "\xB4",
  45. '184' => "\xB8",
  46. '193' => "\xC1",
  47. '194' => "\xC2",
  48. '196' => "\xC4",
  49. '199' => "\xC7",
  50. '201' => "\xC9",
  51. '203' => "\xCB",
  52. '205' => "\xCD",
  53. '206' => "\xCE",
  54. '211' => "\xD3",
  55. '212' => "\xD4",
  56. '214' => "\xD6",
  57. '215' => "\xD7",
  58. '218' => "\xDA",
  59. '220' => "\xDC",
  60. '221' => "\xDD",
  61. '223' => "\xDF",
  62. '225' => "\xE1",
  63. '226' => "\xE2",
  64. '228' => "\xE4",
  65. '231' => "\xE7",
  66. '233' => "\xE9",
  67. '235' => "\xEB",
  68. '237' => "\xED",
  69. '238' => "\xEE",
  70. '243' => "\xF3",
  71. '244' => "\xF4",
  72. '246' => "\xF6",
  73. '247' => "\xF7",
  74. '250' => "\xFA",
  75. '252' => "\xFC",
  76. '253' => "\xFD",
  77. '258' => "\xC3",
  78. '259' => "\xE3",
  79. '260' => "\xA1",
  80. '261' => "\xB1",
  81. '262' => "\xC6",
  82. '263' => "\xE6",
  83. '268' => "\xC8",
  84. '269' => "\xE8",
  85. '270' => "\xCF",
  86. '271' => "\xEF",
  87. '272' => "\xD0",
  88. '273' => "\xF0",
  89. '280' => "\xCA",
  90. '281' => "\xEA",
  91. '282' => "\xCC",
  92. '283' => "\xEC",
  93. '313' => "\xC5",
  94. '314' => "\xE5",
  95. '317' => "\xA5",
  96. '318' => "\xB5",
  97. '321' => "\xA3",
  98. '322' => "\xB3",
  99. '323' => "\xD1",
  100. '324' => "\xF1",
  101. '327' => "\xD2",
  102. '328' => "\xF2",
  103. '336' => "\xD5",
  104. '337' => "\xF5",
  105. '340' => "\xC0",
  106. '341' => "\xE0",
  107. '344' => "\xD8",
  108. '345' => "\xF8",
  109. '346' => "\xA6",
  110. '347' => "\xB6",
  111. '350' => "\xAA",
  112. '351' => "\xBA",
  113. '352' => "\xA9",
  114. '353' => "\xB9",
  115. '354' => "\xDE",
  116. '355' => "\xFE",
  117. '356' => "\xAB",
  118. '357' => "\xBB",
  119. '366' => "\xD9",
  120. '367' => "\xF9",
  121. '368' => "\xDB",
  122. '369' => "\xFB",
  123. '377' => "\xAC",
  124. '378' => "\xBC",
  125. '379' => "\xAF",
  126. '380' => "\xBF",
  127. '381' => "\xAE",
  128. '382' => "\xBE",
  129. '711' => "\xB7",
  130. '728' => "\xA2",
  131. '729' => "\xFF",
  132. '731' => "\xB2",
  133. '733' => "\xBD");
  134. if (array_key_exists($var,$iso88592chars)) {
  135. $ret=$iso88592chars[$var];
  136. } else {
  137. $ret='?';
  138. }
  139. return $ret;
  140. }