1--TEST--
2mb_detect_encoding()
3--SKIPIF--
4<?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5--INI--
6mbstring.language=Japanese
7--FILE--
8<?php
9// TODO: Add more tests
10
11// SJIS string (BASE64 encoded)
12$sjis = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
13// JIS string (BASE64 encoded)
14$jis = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
15// EUC-JP string
16$euc_jp = '���ܸ�ƥ����ȤǤ���01234������������';
17
18// Test with sigle "form encoding"
19// Note: For some reason it complains, results are differ. Not reserched.
20echo "== BASIC TEST ==\n";
21$s = $sjis;
22$s = mb_detect_encoding($s, 'SJIS');
23print("SJIS: $s\n");
24
25$s = $jis;
26$s = mb_detect_encoding($s, 'JIS');
27print("JIS: $s\n");
28
29$s = $euc_jp;
30$s = mb_detect_encoding($s, 'UTF-8,EUC-JP,JIS');
31print("EUC-JP: $s\n");
32
33$s = $euc_jp;
34$s = mb_detect_encoding($s, 'JIS,EUC-JP');
35print("EUC-JP: $s\n");
36
37
38
39// Using Encoding List Array
40echo "== ARRAY ENCODING LIST ==\n";
41
42$a = array(0=>'UTF-8',1=>'EUC-JP', 2=>'SJIS', 3=>'JIS');
43
44// Note: Due to detect order, detected as UTF-8
45$s = $jis;
46$s = mb_detect_encoding($s, $a);
47print("JIS: $s\n");
48
49$s = $euc_jp;
50$s = mb_detect_encoding($s, $a);
51print("EUC-JP: $s\n");
52
53$s = $sjis;
54$s = mb_detect_encoding($s, $a);
55print("SJIS: $s\n");
56
57
58// Using Detect Order
59echo "== DETECT ORDER ==\n";
60
61mb_detect_order('auto');
62
63
64$s = $jis;
65$s = mb_detect_encoding($s);
66print("JIS: $s\n");
67
68$s = $euc_jp;
69$s = mb_detect_encoding($s);
70print("EUC-JP: $s\n");
71
72$s = $sjis;
73$s = mb_detect_encoding($s);
74print("SJIS: $s\n");
75
76
77// Invalid(?) Parameters
78echo "== INVALID PARAMETER ==\n";
79
80$s = mb_detect_encoding(1234, 'EUC-JP');
81print("INT: $s\n"); // EUC-JP
82
83$s = mb_detect_encoding('', 'EUC-JP');
84print("EUC-JP: $s\n");  // SJIS
85
86$s = $euc_jp;
87$s = mb_detect_encoding($s, 'BAD');
88print("BAD: $s\n"); // BAD
89
90$s = $euc_jp;
91$s = mb_detect_encoding();
92print("MP: $s\n"); // Missing parameter
93
94
95?>
96--EXPECTF--
97== BASIC TEST ==
98SJIS: SJIS
99JIS: JIS
100EUC-JP: EUC-JP
101EUC-JP: EUC-JP
102== ARRAY ENCODING LIST ==
103JIS: UTF-8
104EUC-JP: EUC-JP
105SJIS: SJIS
106== DETECT ORDER ==
107JIS: JIS
108EUC-JP: EUC-JP
109SJIS: SJIS
110== INVALID PARAMETER ==
111INT: EUC-JP
112EUC-JP: EUC-JP
113
114Warning: mb_detect_encoding(): Illegal argument in %s on line %d
115BAD: EUC-JP
116
117Warning: mb_detect_encoding() expects at least 1 parameter, 0 given in %s on line %d
118MP:
119