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--EXPECT--
112== BASIC TEST ==
113EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
114EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
115SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
116JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
117== STRING ENCODING LIST ==
118EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
119SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
120JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
121== ARRAY ENCODING LIST ==
122EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
123SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
124JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
125== DETECT ORDER ==
126EUC-JP: ���ܸ�ƥ����ȤǤ���01234������������
127SJIS: k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==
128JIS: GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==
129== INVALID PARAMETER ==
130INT: 1234
131EUC-JP:
132ERR: Warning
133BAD:
134ERR: Warning
135MP:
136