Annotation of embedaddon/php/ext/mbstring/tests/mb_detect_encoding.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: mb_detect_encoding()
3: --SKIPIF--
4: <?php extension_loaded('mbstring') or die('skip mbstring not available'); ?>
5: --INI--
6: mbstring.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
11: ini_set('include_path', dirname(__FILE__));
12: include_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 = '日本語テキストです。0123456789。';
20:
21: // Test with sigle "form encoding"
22: // Note: For some reason it complains, results are differ. Not reserched.
23: echo "== BASIC TEST ==\n";
24: $s = $sjis;
25: $s = mb_detect_encoding($s, 'SJIS');
26: print("SJIS: $s\n");
27:
28: $s = $jis;
29: $s = mb_detect_encoding($s, 'JIS');
30: print("JIS: $s\n");
31:
32: $s = $euc_jp;
33: $s = mb_detect_encoding($s, 'UTF-8,EUC-JP,JIS');
34: print("EUC-JP: $s\n");
35:
36: $s = $euc_jp;
37: $s = mb_detect_encoding($s, 'JIS,EUC-JP');
38: print("EUC-JP: $s\n");
39:
40:
41:
42: // Using Encoding List Array
43: echo "== 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);
50: print("JIS: $s\n");
51:
52: $s = $euc_jp;
53: $s = mb_detect_encoding($s, $a);
54: print("EUC-JP: $s\n");
55:
56: $s = $sjis;
57: $s = mb_detect_encoding($s, $a);
58: print("SJIS: $s\n");
59:
60:
61: // Using Detect Order
62: echo "== DETECT ORDER ==\n";
63:
64: mb_detect_order('auto');
65:
66:
67: $s = $jis;
68: $s = mb_detect_encoding($s);
69: print("JIS: $s\n");
70:
71: $s = $euc_jp;
72: $s = mb_detect_encoding($s);
73: print("EUC-JP: $s\n");
74:
75: $s = $sjis;
76: $s = mb_detect_encoding($s);
77: print("SJIS: $s\n");
78:
79:
80: // Invalid(?) Parameters
81: echo "== INVALID PARAMETER ==\n";
82:
83: $s = mb_detect_encoding(1234, 'EUC-JP');
84: print("INT: $s\n"); // EUC-JP
85:
86: $s = mb_detect_encoding('', 'EUC-JP');
87: print("EUC-JP: $s\n"); // SJIS
88:
89: $s = $euc_jp;
90: $s = mb_detect_encoding($s, 'BAD');
91: print("BAD: $s\n"); // BAD
92:
93: $s = $euc_jp;
94: $s = mb_detect_encoding();
95: print("MP: $s\n"); // Missing parameter
96:
97:
98: ?>
99:
100: --EXPECT--
101: == BASIC TEST ==
102: SJIS: SJIS
103: JIS: JIS
104: EUC-JP: EUC-JP
105: EUC-JP: EUC-JP
106: == ARRAY ENCODING LIST ==
107: JIS: UTF-8
108: EUC-JP: EUC-JP
109: SJIS: SJIS
110: == DETECT ORDER ==
111: JIS: JIS
112: EUC-JP: EUC-JP
113: SJIS: SJIS
114: == INVALID PARAMETER ==
115: INT: EUC-JP
116: EUC-JP: EUC-JP
117: ERR: Warning
118: BAD: EUC-JP
119: ERR: Warning
120: MP:
121:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>