tis_620.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * @version $Id$
  9. * @copyright Copyright &copy; 2004-2005 The SquirrelMail Project Team
  10. * @package squirrelmail
  11. * @subpackage encode
  12. */
  13. /**
  14. * Converts string to tis-620
  15. * @param string $string text with numeric unicode entities
  16. * @return string tis-620 encoded text
  17. */
  18. function charset_encode_tis_620 ($string) {
  19. // don't run encoding function, if there is no encoded characters
  20. if (! preg_match("'&#[0-9]+;'",$string) ) return $string;
  21. $string=preg_replace("/&#([0-9]+);/e","unicodetotis620('\\1')",$string);
  22. // $string=preg_replace("/&#[xX]([0-9A-F]+);/e","unicodetotis620(hexdec('\\1'))",$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 int $var decimal unicode value
  34. * @return string tis-620 character
  35. */
  36. function unicodetotis620($var) {
  37. $tis620chars=array('3585' => "\xA1",
  38. '3586' => "\xA2",
  39. '3587' => "\xA3",
  40. '3588' => "\xA4",
  41. '3589' => "\xA5",
  42. '3590' => "\xA6",
  43. '3591' => "\xA7",
  44. '3592' => "\xA8",
  45. '3593' => "\xA9",
  46. '3594' => "\xAA",
  47. '3595' => "\xAB",
  48. '3596' => "\xAC",
  49. '3597' => "\xAD",
  50. '3598' => "\xAE",
  51. '3599' => "\xAF",
  52. '3600' => "\xB0",
  53. '3601' => "\xB1",
  54. '3602' => "\xB2",
  55. '3603' => "\xB3",
  56. '3604' => "\xB4",
  57. '3605' => "\xB5",
  58. '3606' => "\xB6",
  59. '3607' => "\xB7",
  60. '3608' => "\xB8",
  61. '3609' => "\xB9",
  62. '3610' => "\xBA",
  63. '3611' => "\xBB",
  64. '3612' => "\xBC",
  65. '3613' => "\xBD",
  66. '3614' => "\xBE",
  67. '3615' => "\xBF",
  68. '3616' => "\xC0",
  69. '3617' => "\xC1",
  70. '3618' => "\xC2",
  71. '3619' => "\xC3",
  72. '3620' => "\xC4",
  73. '3621' => "\xC5",
  74. '3622' => "\xC6",
  75. '3623' => "\xC7",
  76. '3624' => "\xC8",
  77. '3625' => "\xC9",
  78. '3626' => "\xCA",
  79. '3627' => "\xCB",
  80. '3628' => "\xCC",
  81. '3629' => "\xCD",
  82. '3630' => "\xCE",
  83. '3631' => "\xCF",
  84. '3632' => "\xD0",
  85. '3633' => "\xD1",
  86. '3634' => "\xD2",
  87. '3635' => "\xD3",
  88. '3636' => "\xD4",
  89. '3637' => "\xD5",
  90. '3638' => "\xD6",
  91. '3639' => "\xD7",
  92. '3640' => "\xD8",
  93. '3641' => "\xD9",
  94. '3642' => "\xDA",
  95. '3647' => "\xDF",
  96. '3648' => "\xE0",
  97. '3649' => "\xE1",
  98. '3650' => "\xE2",
  99. '3651' => "\xE3",
  100. '3652' => "\xE4",
  101. '3653' => "\xE5",
  102. '3654' => "\xE6",
  103. '3655' => "\xE7",
  104. '3656' => "\xE8",
  105. '3657' => "\xE9",
  106. '3658' => "\xEA",
  107. '3659' => "\xEB",
  108. '3660' => "\xEC",
  109. '3661' => "\xED",
  110. '3662' => "\xEE",
  111. '3663' => "\xEF",
  112. '3664' => "\xF0",
  113. '3665' => "\xF1",
  114. '3666' => "\xF2",
  115. '3667' => "\xF3",
  116. '3668' => "\xF4",
  117. '3669' => "\xF5",
  118. '3670' => "\xF6",
  119. '3671' => "\xF7",
  120. '3672' => "\xF8",
  121. '3673' => "\xF9",
  122. '3674' => "\xFA",
  123. '3675' => "\xFB");
  124. if (array_key_exists($var,$tis620chars)) {
  125. $ret=$tis620chars[$var];
  126. } else {
  127. $ret='?';
  128. }
  129. return $ret;
  130. }
  131. ?>