charset_conversion.lib.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Charset conversion functions.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. define('PMA_CHARSET_NONE', 0);
  12. define('PMA_CHARSET_ICONV', 1);
  13. define('PMA_CHARSET_RECODE', 2);
  14. define('PMA_CHARSET_ICONV_AIX', 3);
  15. // Finally detect which function we will use:
  16. if ($cfg['RecodingEngine'] == 'iconv') {
  17. if (@function_exists('iconv')) {
  18. if ((@stristr(PHP_OS, 'AIX'))
  19. && (@strcasecmp(ICONV_IMPL, 'unknown') == 0)
  20. && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)
  21. ) {
  22. $PMA_recoding_engine = PMA_CHARSET_ICONV_AIX;
  23. } else {
  24. $PMA_recoding_engine = PMA_CHARSET_ICONV;
  25. }
  26. } else {
  27. $PMA_recoding_engine = PMA_CHARSET_NONE;
  28. PMA_warnMissingExtension('iconv');
  29. }
  30. } elseif ($cfg['RecodingEngine'] == 'recode') {
  31. if (@function_exists('recode_string')) {
  32. $PMA_recoding_engine = PMA_CHARSET_RECODE;
  33. } else {
  34. $PMA_recoding_engine = PMA_CHARSET_NONE;
  35. PMA_warnMissingExtension('recode');
  36. }
  37. } elseif ($cfg['RecodingEngine'] == 'auto') {
  38. if (@function_exists('iconv')) {
  39. if ((@stristr(PHP_OS, 'AIX'))
  40. && (@strcasecmp(ICONV_IMPL, 'unknown') == 0)
  41. && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)
  42. ) {
  43. $PMA_recoding_engine = PMA_CHARSET_ICONV_AIX;
  44. } else {
  45. $PMA_recoding_engine = PMA_CHARSET_ICONV;
  46. }
  47. } elseif (@function_exists('recode_string')) {
  48. $PMA_recoding_engine = PMA_CHARSET_RECODE;
  49. } else {
  50. $PMA_recoding_engine = PMA_CHARSET_NONE;
  51. }
  52. } else {
  53. $PMA_recoding_engine = PMA_CHARSET_NONE;
  54. }
  55. /* Load AIX iconv wrapper if needed */
  56. if ($PMA_recoding_engine == PMA_CHARSET_ICONV_AIX) {
  57. include_once './libraries/iconv_wrapper.lib.php';
  58. }
  59. /**
  60. * Converts encoding of text according to parameters with detected
  61. * conversion function.
  62. *
  63. * @param string $src_charset source charset
  64. * @param string $dest_charset target charset
  65. * @param string $what what to convert
  66. *
  67. * @return string converted text
  68. *
  69. * @access public
  70. *
  71. */
  72. function PMA_convert_string($src_charset, $dest_charset, $what)
  73. {
  74. if ($src_charset == $dest_charset) {
  75. return $what;
  76. }
  77. switch ($GLOBALS['PMA_recoding_engine']) {
  78. case PMA_CHARSET_RECODE:
  79. return recode_string($src_charset . '..' . $dest_charset, $what);
  80. case PMA_CHARSET_ICONV:
  81. return iconv(
  82. $src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what
  83. );
  84. case PMA_CHARSET_ICONV_AIX:
  85. return PMA_aix_iconv_wrapper(
  86. $src_charset, $dest_charset . $GLOBALS['cfg']['IconvExtraParams'], $what
  87. );
  88. default:
  89. return $what;
  90. }
  91. } // end of the "PMA_convert_string()" function
  92. ?>