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