tis_620.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * tis-620 encoding functions
  4. *
  5. * takes a string of unicode entities and converts it to a tis-620 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 tis-620
  16. * @param string $string text with numeric unicode entities
  17. * @return string tis-620 encoded text
  18. */
  19. function charset_encode_tis_620 ($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]+);/",'unicodetotis620',$string);
  23. return $string;
  24. }
  25. /**
  26. * Return tis-620 symbol when unicode character number is provided
  27. *
  28. * This function is used internally by charset_encode_tis_620
  29. * function. It might be unavailable to other SquirrelMail functions.
  30. * Don't use it or make sure, that functions/encode/tis_620.php is
  31. * included.
  32. *
  33. * @param array $matches array with first element a decimal unicode value
  34. * @return string tis-620 character
  35. */
  36. function unicodetotis620($matches) {
  37. $var = $matches[1];
  38. $tis620chars=array('3585' => "\xA1",
  39. '3586' => "\xA2",
  40. '3587' => "\xA3",
  41. '3588' => "\xA4",
  42. '3589' => "\xA5",
  43. '3590' => "\xA6",
  44. '3591' => "\xA7",
  45. '3592' => "\xA8",
  46. '3593' => "\xA9",
  47. '3594' => "\xAA",
  48. '3595' => "\xAB",
  49. '3596' => "\xAC",
  50. '3597' => "\xAD",
  51. '3598' => "\xAE",
  52. '3599' => "\xAF",
  53. '3600' => "\xB0",
  54. '3601' => "\xB1",
  55. '3602' => "\xB2",
  56. '3603' => "\xB3",
  57. '3604' => "\xB4",
  58. '3605' => "\xB5",
  59. '3606' => "\xB6",
  60. '3607' => "\xB7",
  61. '3608' => "\xB8",
  62. '3609' => "\xB9",
  63. '3610' => "\xBA",
  64. '3611' => "\xBB",
  65. '3612' => "\xBC",
  66. '3613' => "\xBD",
  67. '3614' => "\xBE",
  68. '3615' => "\xBF",
  69. '3616' => "\xC0",
  70. '3617' => "\xC1",
  71. '3618' => "\xC2",
  72. '3619' => "\xC3",
  73. '3620' => "\xC4",
  74. '3621' => "\xC5",
  75. '3622' => "\xC6",
  76. '3623' => "\xC7",
  77. '3624' => "\xC8",
  78. '3625' => "\xC9",
  79. '3626' => "\xCA",
  80. '3627' => "\xCB",
  81. '3628' => "\xCC",
  82. '3629' => "\xCD",
  83. '3630' => "\xCE",
  84. '3631' => "\xCF",
  85. '3632' => "\xD0",
  86. '3633' => "\xD1",
  87. '3634' => "\xD2",
  88. '3635' => "\xD3",
  89. '3636' => "\xD4",
  90. '3637' => "\xD5",
  91. '3638' => "\xD6",
  92. '3639' => "\xD7",
  93. '3640' => "\xD8",
  94. '3641' => "\xD9",
  95. '3642' => "\xDA",
  96. '3647' => "\xDF",
  97. '3648' => "\xE0",
  98. '3649' => "\xE1",
  99. '3650' => "\xE2",
  100. '3651' => "\xE3",
  101. '3652' => "\xE4",
  102. '3653' => "\xE5",
  103. '3654' => "\xE6",
  104. '3655' => "\xE7",
  105. '3656' => "\xE8",
  106. '3657' => "\xE9",
  107. '3658' => "\xEA",
  108. '3659' => "\xEB",
  109. '3660' => "\xEC",
  110. '3661' => "\xED",
  111. '3662' => "\xEE",
  112. '3663' => "\xEF",
  113. '3664' => "\xF0",
  114. '3665' => "\xF1",
  115. '3666' => "\xF2",
  116. '3667' => "\xF3",
  117. '3668' => "\xF4",
  118. '3669' => "\xF5",
  119. '3670' => "\xF6",
  120. '3671' => "\xF7",
  121. '3672' => "\xF8",
  122. '3673' => "\xF9",
  123. '3674' => "\xFA",
  124. '3675' => "\xFB");
  125. if (array_key_exists($var,$tis620chars)) {
  126. $ret=$tis620chars[$var];
  127. } else {
  128. $ret='?';
  129. }
  130. return $ret;
  131. }