1--TEST--
2Test mb_convert_encoding() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_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/*
16 * Test basic functionality of mb_convert_encoding()
17 */
18
19echo "*** Testing mb_convert_encoding() : basic functionality ***\n";
20
21//All strings are the same when displayed in their respective encodings
22$sjis_string = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
23$jis_string = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
24$euc_jp_string = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==');
25$utf8_string = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
26
27echo "\n-- Convert to JIS --\n";
28echo "JIS encoded string in base64:\n";
29var_dump(base64_encode($jis_string));
30echo "Converted Strings:\n";
31var_dump(base64_encode(mb_convert_encoding($sjis_string, 'JIS', 'SJIS')));
32var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'JIS', 'EUC-JP')));
33var_dump(base64_encode(mb_convert_encoding($utf8_string, 'JIS', 'UTF-8')));
34
35echo "\n-- Convert to EUC-JP --\n";
36echo "EUC-JP encoded string in base64:\n";
37var_dump(base64_encode($euc_jp_string));
38echo "Converted Strings:\n";
39var_dump(base64_encode(mb_convert_encoding($sjis_string, 'EUC-JP', 'SJIS')));
40var_dump(base64_encode(mb_convert_encoding($jis_string, 'EUC-JP', 'JIS')));
41var_dump(base64_encode(mb_convert_encoding($utf8_string, 'EUC-JP', 'UTF-8')));
42
43echo "\n-- Convert to SJIS --\n";
44echo "SJIS encoded string in base64:\n";
45var_dump(base64_encode($sjis_string));
46echo "Converted Strings:\n";
47var_dump(base64_encode(mb_convert_encoding($jis_string, 'SJIS', 'JIS')));
48var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'SJIS', 'EUC-JP')));
49var_dump(base64_encode(mb_convert_encoding($utf8_string, 'SJIS', 'UTF-8')));
50
51echo "\n-- Convert to UTF-8 --\n";
52echo "UTF-8 encoded string in base64:\n";
53var_dump(base64_encode($utf8_string));
54echo "Converted Strings:\n";
55var_dump(base64_encode(mb_convert_encoding($sjis_string, 'UTF-8', 'SJIS')));
56var_dump(base64_encode(mb_convert_encoding($jis_string, 'UTF-8', 'JIS')));
57var_dump(base64_encode(mb_convert_encoding($euc_jp_string, 'UTF-8', 'EUC-JP')));
58
59echo "Done";
60?>
61--EXPECT--
62*** Testing mb_convert_encoding() : basic functionality ***
63
64-- Convert to JIS --
65JIS encoded string in base64:
66string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
67Converted Strings:
68string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
69string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
70string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=="
71
72-- Convert to EUC-JP --
73EUC-JP encoded string in base64:
74string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
75Converted Strings:
76string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
77string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
78string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=="
79
80-- Convert to SJIS --
81SJIS encoded string in base64:
82string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
83Converted Strings:
84string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
85string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
86string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=="
87
88-- Convert to UTF-8 --
89UTF-8 encoded string in base64:
90string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
91Converted Strings:
92string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
93string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
94string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII="
95Done
96