PageRenderTime 29ms CodeModel.GetById 21ms RepoModel.GetById 24ms app.codeStats 0ms

/manage/phpmyadminlite/libraries/kanji-encoding.lib.php

https://gitlab.com/albert925/lading-ach
PHP | 152 lines | 71 code | 20 blank | 61 comment | 23 complexity | 9de1d3ea325433312c7ae776e6921da1 MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Set of functions for kanji-encoding convert (available only with japanese
  5. * language)
  6. *
  7. * PHP4 configure requirements:
  8. * --enable-mbstring --enable-mbstr-enc-trans --enable-mbregex
  9. *
  10. * 2002/2/22 - by Yukihiro Kawada <kawada@den.fujifilm.co.jp>
  11. *
  12. * @version $Id$
  13. * @package phpMyAdmin
  14. */
  15. if (! defined('PHPMYADMIN')) {
  16. exit;
  17. }
  18. /**
  19. * Gets the php internal encoding codes and sets the available encoding
  20. * codes list
  21. * 2002/1/4 by Y.Kawada
  22. *
  23. * @global string the current encoding code
  24. * @global string the available encoding codes list
  25. *
  26. * @return boolean always true
  27. */
  28. function PMA_internal_enc_check() {
  29. global $internal_enc, $enc_list;
  30. $internal_enc = mb_internal_encoding();
  31. if ($internal_enc == 'EUC-JP') {
  32. $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
  33. } else {
  34. $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
  35. }
  36. return TRUE;
  37. } // end of the 'PMA_internal_enc_check' function
  38. /**
  39. * Reverses SJIS & EUC-JP position in the encoding codes list
  40. * 2002/1/4 by Y.Kawada
  41. *
  42. * @global string the available encoding codes list
  43. *
  44. * @return boolean always true
  45. */
  46. function PMA_change_enc_order() {
  47. global $enc_list;
  48. $p = explode(',', $enc_list);
  49. if ($p[1] == 'EUC-JP') {
  50. $enc_list = 'ASCII,SJIS,EUC-JP,JIS';
  51. } else {
  52. $enc_list = 'ASCII,EUC-JP,SJIS,JIS';
  53. }
  54. return TRUE;
  55. } // end of the 'PMA_change_enc_order' function
  56. /**
  57. * Kanji string encoding convert
  58. * 2002/1/4 by Y.Kawada
  59. *
  60. * @param string the string to convert
  61. * @param string the destinasion encoding code
  62. * @param string set 'kana' convert to JIS-X208-kana
  63. *
  64. * @global string the available encoding codes list
  65. *
  66. * @return string the converted string
  67. */
  68. function PMA_kanji_str_conv($str, $enc, $kana) {
  69. global $enc_list;
  70. if ($enc == '' && $kana == '') {
  71. return $str;
  72. }
  73. $nw = mb_detect_encoding($str, $enc_list);
  74. if ($kana == 'kana') {
  75. $dist = mb_convert_kana($str, 'KV', $nw);
  76. $str = $dist;
  77. }
  78. if ($nw != $enc && $enc != '') {
  79. $dist = mb_convert_encoding($str, $enc, $nw);
  80. } else {
  81. $dist = $str;
  82. }
  83. return $dist;
  84. } // end of the 'PMA_kanji_str_conv' function
  85. /**
  86. * Kanji file encoding convert
  87. * 2002/1/4 by Y.Kawada
  88. *
  89. * @param string the name of the file to convert
  90. * @param string the destinasion encoding code
  91. * @param string set 'kana' convert to JIS-X208-kana
  92. *
  93. * @return string the name of the converted file
  94. */
  95. function PMA_kanji_file_conv($file, $enc, $kana) {
  96. if ($enc == '' && $kana == '') {
  97. return $file;
  98. }
  99. $tmpfname = tempnam('', $enc);
  100. $fpd = fopen($tmpfname, 'wb');
  101. $fps = fopen($file, 'r');
  102. PMA_change_enc_order();
  103. while (!feof($fps)) {
  104. $line = fgets($fps, 4096);
  105. $dist = PMA_kanji_str_conv($line, $enc, $kana);
  106. fputs($fpd, $dist);
  107. } // end while
  108. PMA_change_enc_order();
  109. fclose($fps);
  110. fclose($fpd);
  111. unlink($file);
  112. return $tmpfname;
  113. } // end of the 'PMA_kanji_file_conv' function
  114. /**
  115. * Defines radio form fields to switch between encoding modes
  116. * 2002/1/4 by Y.Kawada
  117. *
  118. * @param string spaces character to prepend the output with
  119. *
  120. * @return string xhtml code for the radio controls
  121. */
  122. function PMA_set_enc_form($spaces) {
  123. return "\n"
  124. . $spaces . '<input type="radio" name="knjenc" value="" checked="checked" />non' . "\n"
  125. . $spaces . '<input type="radio" name="knjenc" value="EUC-JP" />EUC' . "\n"
  126. . $spaces . '<input type="radio" name="knjenc" value="SJIS" />SJIS' . "\n"
  127. . $spaces . '&nbsp;' . $GLOBALS['strEncto'] . '<br />' . "\n"
  128. . $spaces . '<input type="checkbox" name="xkana" value="kana" />' . "\n"
  129. . $spaces . '&nbsp;' . $GLOBALS['strXkana'] . '<br />' . "\n";
  130. } // end of the 'PMA_set_enc_form' function
  131. PMA_internal_enc_check();
  132. ?>