iconv_wrapper.lib.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Iconv wrapper for AIX
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * GNU iconv code set to IBM AIX libiconv code set table
  13. * Keys of this table should be in lowercase,
  14. * and searches should be performed using lowercase!
  15. */
  16. $gnu_iconv_to_aix_iconv_codepage_map = array (
  17. // "iso-8859-[1-9]" --> "ISO8859-[1-9]" according to
  18. // http://publibn.boulder.ibm.com/doc_link/en_US/
  19. // a_doc_lib/libs/basetrf2/setlocale.htm
  20. 'iso-8859-1' => 'ISO8859-1',
  21. 'iso-8859-2' => 'ISO8859-2',
  22. 'iso-8859-3' => 'ISO8859-3',
  23. 'iso-8859-4' => 'ISO8859-4',
  24. 'iso-8859-5' => 'ISO8859-5',
  25. 'iso-8859-6' => 'ISO8859-6',
  26. 'iso-8859-7' => 'ISO8859-7',
  27. 'iso-8859-8' => 'ISO8859-8',
  28. 'iso-8859-9' => 'ISO8859-9',
  29. // "big5" --> "IBM-eucTW" according to
  30. // http://kadesh.cepba.upc.es/mancpp/classref/ref/ITranscoder_DSC.htm
  31. 'big5' => 'IBM-eucTW',
  32. // Other mappings corresponding to the phpMyAdmin dropdown box when using the
  33. // charset conversion feature
  34. 'euc-jp' => 'IBM-eucJP',
  35. 'koi8-r' => 'IBM-eucKR',
  36. 'ks_c_5601-1987' => 'KSC5601.1987-0',
  37. 'tis-620' => 'TIS-620',
  38. 'utf-8' => 'UTF-8'
  39. );
  40. /**
  41. * Wrapper around IBM AIX iconv(), whose character set naming differs
  42. * from the GNU version of iconv().
  43. *
  44. * @param string $in_charset input character set
  45. * @param string $out_charset output character set
  46. * @param string $str the string to convert
  47. *
  48. * @return mixed converted string or false on failure
  49. *
  50. * @access public
  51. *
  52. */
  53. function PMA_convertAIXIconv($in_charset, $out_charset, $str)
  54. {
  55. list($in_charset, $out_charset) = PMA_convertAIXMapCharsets(
  56. $in_charset, $out_charset
  57. );
  58. // Call iconv() with the possibly modified parameters
  59. return iconv($in_charset, $out_charset, $str);
  60. } // end of the "PMA_convertAIXIconv()" function
  61. /**
  62. * Maps input and output character set names to corresponding AIX ones
  63. *
  64. * @param string $in_charset input character set
  65. * @param string $out_charset output character set
  66. *
  67. * @return array array of mapped input and output character set names
  68. */
  69. function PMA_convertAIXMapCharsets($in_charset, $out_charset)
  70. {
  71. global $gnu_iconv_to_aix_iconv_codepage_map;
  72. // Check for transliteration argument at the end of output character set name
  73. $translit_search = strpos(strtolower($out_charset), '//translit');
  74. $using_translit = (!($translit_search === false));
  75. // Extract "plain" output character set name
  76. // (without any transliteration argument)
  77. $out_charset_plain = ($using_translit
  78. ? substr($out_charset, 0, $translit_search)
  79. : $out_charset);
  80. // Transform name of input character set (if found)
  81. $in_charset_exisits = array_key_exists(
  82. strtolower($in_charset),
  83. $gnu_iconv_to_aix_iconv_codepage_map
  84. );
  85. if ($in_charset_exisits) {
  86. $in_charset = $gnu_iconv_to_aix_iconv_codepage_map[strtolower($in_charset)];
  87. }
  88. // Transform name of "plain" output character set (if found)
  89. $out_charset_plain_exists = array_key_exists(
  90. strtolower($out_charset_plain),
  91. $gnu_iconv_to_aix_iconv_codepage_map
  92. );
  93. if ($out_charset_plain_exists) {
  94. $out_charset_plain = $gnu_iconv_to_aix_iconv_codepage_map[
  95. strtolower($out_charset_plain)];
  96. }
  97. // Add transliteration argument again (exactly as specified by user) if used
  98. // Build the output character set name that we will use
  99. $out_charset = ($using_translit
  100. ? $out_charset_plain . substr($out_charset, $translit_search)
  101. : $out_charset_plain);
  102. // NOTE: Transliteration not supported; we will use the "plain"
  103. // output character set name
  104. $out_charset = $out_charset_plain;
  105. return array($in_charset, $out_charset);
  106. }
  107. ?>