mb_convert_encoding_basic.phpt 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --TEST--
  2. Test mb_convert_encoding() function : basic functionality
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_convert_encoding') or die("skip mb_convert_encoding() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : string mb_convert_encoding(string $str, string $to_encoding [, mixed $from_encoding])
  11. * Description: Returns converted string in desired encoding
  12. * Source code: ext/mbstring/mbstring.c
  13. */
  14. /*
  15. * Test basic functionality of mb_convert_encoding()
  16. */
  17. echo "*** Testing mb_convert_encoding() : basic functionality ***\n";
  18. //All strings are the same when displayed in their respective encodings
  19. $sjis_string = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
  20. $jis_string = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
  21. $euc_jp_string = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==');
  22. $utf8_string = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  23. echo "\n-- Convert to JIS --\n";
  24. echo "JIS encoded string in base64:\n";
  25. var_dump(base64_encode($jis_string));
  26. echo "Converted Strings:\n";
  27. var_dump(base64_encode(mb_convert_encoding($sjis_string, 'JIS', 'SJIS')));
  28. var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'JIS', 'EUC-JP')));
  29. var_dump(base64_encode(mb_convert_encoding($utf8_string, 'JIS', 'UTF-8')));
  30. echo "\n-- Convert to EUC-JP --\n";
  31. echo "EUC-JP encoded string in base64:\n";
  32. var_dump(base64_encode($euc_jp_string));
  33. echo "Converted Strings:\n";
  34. var_dump(base64_encode(mb_convert_encoding($sjis_string, 'EUC-JP', 'SJIS')));
  35. var_dump(base64_encode(mb_convert_encoding($jis_string, 'EUC-JP', 'JIS')));
  36. var_dump(base64_encode(mb_convert_encoding($utf8_string, 'EUC-JP', 'UTF-8')));
  37. echo "\n-- Convert to SJIS --\n";
  38. echo "SJIS encoded string in base64:\n";
  39. var_dump(base64_encode($sjis_string));
  40. echo "Converted Strings:\n";
  41. var_dump(base64_encode(mb_convert_encoding($jis_string, 'SJIS', 'JIS')));
  42. var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'SJIS', 'EUC-JP')));
  43. var_dump(base64_encode(mb_convert_encoding($utf8_string, 'SJIS', 'UTF-8')));
  44. echo "\n-- Convert to UTF-8 --\n";
  45. echo "UTF-8 encoded string in base64:\n";
  46. var_dump(base64_encode($utf8_string));
  47. echo "Converted Strings:\n";
  48. var_dump(base64_encode(mb_convert_encoding($sjis_string, 'UTF-8', 'SJIS')));
  49. var_dump(base64_encode(mb_convert_encoding($jis_string, 'UTF-8', 'JIS')));
  50. var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'UTF-8', 'EUC-JP')));
  51. echo "Done";
  52. ?>
  53. --EXPECTF--
  54. *** Testing mb_convert_encoding() : basic functionality ***
  55. -- Convert to JIS --
  56. JIS encoded string in base64:
  57. string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
  58. Converted Strings:
  59. string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
  60. string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
  61. string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
  62. -- Convert to EUC-JP --
  63. EUC-JP encoded string in base64:
  64. string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
  65. Converted Strings:
  66. string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
  67. string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
  68. string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
  69. -- Convert to SJIS --
  70. SJIS encoded string in base64:
  71. string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
  72. Converted Strings:
  73. string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
  74. string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
  75. string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
  76. -- Convert to UTF-8 --
  77. UTF-8 encoded string in base64:
  78. string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
  79. Converted Strings:
  80. string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
  81. string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
  82. string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
  83. Done