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