/gui/tools/webmail/functions/encode/iso_8859_9.php

https://github.com/BenBE/ispCP · PHP · 148 lines · 110 code · 8 blank · 30 comment · 3 complexity · d6117ea70ab17950d36b690be82ef20e MD5 · raw file

  1. <?php
  2. /**
  3. * iso-8859-9 encoding functions
  4. *
  5. * takes a string of unicode entities and converts it to a iso-8859-9 encoded string
  6. * Unsupported characters are replaced with ?.
  7. *
  8. * @copyright 2004-2011 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: iso_8859_9.php 14084 2011-01-06 02:44:03Z pdontthink $
  11. * @package squirrelmail
  12. * @subpackage encode
  13. */
  14. /**
  15. * Converts string to iso-8859-9
  16. * @param string $string text with numeric unicode entities
  17. * @return string iso-8859-9 encoded text
  18. */
  19. function charset_encode_iso_8859_9 ($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","unicodetoiso88599('\\1')",$string);
  23. // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetoiso88599(hexdec('\\1'))",$string);
  24. return $string;
  25. }
  26. /**
  27. * Return iso-8859-9 symbol when unicode character number is provided
  28. *
  29. * This function is used internally by charset_encode_iso_8859_9
  30. * function. It might be unavailable to other SquirrelMail functions.
  31. * Don't use it or make sure, that functions/encode/iso_8859_9.php is
  32. * included.
  33. *
  34. * @param int $var decimal unicode value
  35. * @return string iso-8859-9 character
  36. */
  37. function unicodetoiso88599($var) {
  38. $iso88599chars=array('160' => "\xA0",
  39. '161' => "\xA1",
  40. '162' => "\xA2",
  41. '163' => "\xA3",
  42. '164' => "\xA4",
  43. '165' => "\xA5",
  44. '166' => "\xA6",
  45. '167' => "\xA7",
  46. '168' => "\xA8",
  47. '169' => "\xA9",
  48. '170' => "\xAA",
  49. '171' => "\xAB",
  50. '172' => "\xAC",
  51. '173' => "\xAD",
  52. '174' => "\xAE",
  53. '175' => "\xAF",
  54. '176' => "\xB0",
  55. '177' => "\xB1",
  56. '178' => "\xB2",
  57. '179' => "\xB3",
  58. '180' => "\xB4",
  59. '181' => "\xB5",
  60. '182' => "\xB6",
  61. '183' => "\xB7",
  62. '184' => "\xB8",
  63. '185' => "\xB9",
  64. '186' => "\xBA",
  65. '187' => "\xBB",
  66. '188' => "\xBC",
  67. '189' => "\xBD",
  68. '190' => "\xBE",
  69. '191' => "\xBF",
  70. '192' => "\xC0",
  71. '193' => "\xC1",
  72. '194' => "\xC2",
  73. '195' => "\xC3",
  74. '196' => "\xC4",
  75. '197' => "\xC5",
  76. '198' => "\xC6",
  77. '199' => "\xC7",
  78. '200' => "\xC8",
  79. '201' => "\xC9",
  80. '202' => "\xCA",
  81. '203' => "\xCB",
  82. '204' => "\xCC",
  83. '205' => "\xCD",
  84. '206' => "\xCE",
  85. '207' => "\xCF",
  86. '209' => "\xD1",
  87. '210' => "\xD2",
  88. '211' => "\xD3",
  89. '212' => "\xD4",
  90. '213' => "\xD5",
  91. '214' => "\xD6",
  92. '215' => "\xD7",
  93. '216' => "\xD8",
  94. '217' => "\xD9",
  95. '218' => "\xDA",
  96. '219' => "\xDB",
  97. '220' => "\xDC",
  98. '223' => "\xDF",
  99. '224' => "\xE0",
  100. '225' => "\xE1",
  101. '226' => "\xE2",
  102. '227' => "\xE3",
  103. '228' => "\xE4",
  104. '229' => "\xE5",
  105. '230' => "\xE6",
  106. '231' => "\xE7",
  107. '232' => "\xE8",
  108. '233' => "\xE9",
  109. '234' => "\xEA",
  110. '235' => "\xEB",
  111. '236' => "\xEC",
  112. '237' => "\xED",
  113. '238' => "\xEE",
  114. '239' => "\xEF",
  115. '241' => "\xF1",
  116. '242' => "\xF2",
  117. '243' => "\xF3",
  118. '244' => "\xF4",
  119. '245' => "\xF5",
  120. '246' => "\xF6",
  121. '247' => "\xF7",
  122. '248' => "\xF8",
  123. '249' => "\xF9",
  124. '250' => "\xFA",
  125. '251' => "\xFB",
  126. '252' => "\xFC",
  127. '255' => "\xFF",
  128. '286' => "\xD0",
  129. '287' => "\xF0",
  130. '304' => "\xDD",
  131. '305' => "\xFD",
  132. '350' => "\xDE",
  133. '351' => "\xFE");
  134. if (array_key_exists($var,$iso88599chars)) {
  135. $ret=$iso88599chars[$var];
  136. } else {
  137. $ret='?';
  138. }
  139. return $ret;
  140. }