1--TEST--
2mb_convert_encoding()
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--INI--
6output_handler=
7mbstring.language=Japanese
8--FILE--
9<?php
10// TODO: Add more tests
11//$debug = true; // Uncomment this line to view error/warning/notice message in *.out file
12ini_set('include_path', dirname(__FILE__));
13include_once('common.inc');
14
15// SJIS string (BASE64 encoded)
16$sjis = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
17// JIS string (BASE64 encoded)
18$jis = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
19// EUC-JP string
20$euc_jp = '���ܸ�ƥ����ȤǤ���01234������������';
21
22// Test with sigle "form encoding"
23// Note: For some reason it complains, results are differ. Not reserched.
24echo "== BASIC TEST ==\n";
25$s = $sjis;
26$s = mb_convert_encoding($s, 'EUC-JP', 'SJIS');
27print("EUC-JP: $s\n"); // EUC-JP
28
29$s = $jis;
30$s = mb_convert_encoding($s, 'EUC-JP', 'JIS');
31print("EUC-JP: $s\n"); // EUC-JP
32
33$s = $euc_jp;
34$s = mb_convert_encoding($s, 'SJIS', 'EUC-JP');
35print("SJIS: ".base64_encode($s)."\n"); // SJIS
36
37$s = $euc_jp;
38$s = mb_convert_encoding($s, 'JIS', 'EUC-JP');
39print("JIS: ".base64_encode($s)."\n"); // JIS
40
41
42// Using Encoding List Array
43echo "== STRING ENCODING LIST ==\n";
44
45$a = 'JIS,UTF-8,EUC-JP,SJIS';
46$s = $jis;
47$s = mb_convert_encoding($s, 'EUC-JP', $a);
48print("EUC-JP: $s\n"); // EUC-JP
49
50$s = $euc_jp;
51$s = mb_convert_encoding($s, 'SJIS', $a);
52print("SJIS: ".base64_encode($s)."\n");  // SJIS
53
54$s = $euc_jp;
55$s = mb_convert_encoding($s, 'JIS', $a);
56print("JIS: ".base64_encode($s)."\n"); // JIS
57
58
59// Using Encoding List Array
60echo "== ARRAY ENCODING LIST ==\n";
61
62$a = array(0=>'JIS', 1=>'UTF-8', 2=>'EUC-JP', 3=>'SJIS');
63$s = $jis;
64$s = mb_convert_encoding($s, 'EUC-JP', $a);
65print("EUC-JP: $s\n"); // EUC-JP
66
67$s = $euc_jp;
68$s = mb_convert_encoding($s, 'SJIS', $a);
69print("SJIS: ".base64_encode($s)."\n");  // SJIS
70
71$s = $euc_jp;
72$s = mb_convert_encoding($s, 'JIS', $a);
73print("JIS: ".base64_encode($s)."\n"); // JIS
74
75
76// Using Detect Order
77echo "== DETECT ORDER ==\n";
78
79$s = $jis;
80$s = mb_convert_encoding($s, 'EUC-JP', 'auto');
81print("EUC-JP: $s\n"); // EUC-JP
82
83$s = $euc_jp;
84$s = mb_convert_encoding($s, 'SJIS', 'auto');
85print("SJIS: ".base64_encode($s)."\n");  // SJIS
86
87$s = $euc_jp;
88$s = mb_convert_encoding($s, 'JIS', 'auto');
89print("JIS: ".base64_encode($s)."\n"); // JIS
90
91
92// Invalid(?) Parameters
93echo "== INVALID PARAMETER ==\n";
94
95$s = mb_convert_encoding(1234, 'EUC-JP');
96print("INT: $s\n"); // EUC-JP
97
98$s = mb_convert_encoding('', 'EUC-JP');
99print("EUC-JP: $s\n");  // SJIS
100
101$s = $euc_jp;
102$s = mb_convert_encoding($s, 'BAD');
103print("BAD: $s\n"); // BAD
104
105$s = $euc_jp;
106$s = mb_convert_encoding($s);
107print("MP: $s\n"); // Missing parameter
108
109
110?>
111
112--EXPECT--
113== BASIC TEST ==
114EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
115EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
116SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
117JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
118== STRING ENCODING LIST ==
119EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
120SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
121JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
122== ARRAY ENCODING LIST ==
123EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
124SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
125JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
126== DETECT ORDER ==
127EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
128SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
129JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
130== INVALID PARAMETER ==
131INT: 1234
132EUC-JP:
133ERR: Warning
134BAD:
135ERR: Warning
136MP:
137
138
139