xref: /PHP-8.0/ext/iconv/tests/iconv_basic.phpt (revision b5c7a83d)
1--TEST--
2Test iconv() function : basic functionality
3--SKIPIF--
4<?php
5extension_loaded('iconv') or die('skip');
6function_exists('iconv') or die("skip iconv() is not available in this build");
7?>
8--FILE--
9<?php
10/*
11 * Test basic functionality of iconv()
12 */
13
14echo "*** Testing iconv() : basic functionality ***\n";
15
16//All strings are the same when displayed in their respective encodings
17$sjis_string = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
18$euc_jp_string = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==');
19$utf8_string = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
20
21echo "\n-- Convert to EUC-JP --\n";
22echo "Expected EUC-JP encoded string in base64:\n";
23var_dump(bin2hex($euc_jp_string));
24echo "Converted Strings:\n";
25var_dump(bin2hex(iconv('SJIS', 'EUC-JP', $sjis_string )));
26var_dump(bin2hex(iconv('UTF-8', 'EUC-JP', $utf8_string)));
27
28echo "\n-- Convert to SJIS --\n";
29echo "Expected SJIS encoded string in base64:\n";
30var_dump(bin2hex($sjis_string));
31echo "Converted Strings:\n";
32var_dump(bin2hex(iconv('EUC-JP', 'SJIS', $euc_jp_string)));
33var_dump(bin2hex(iconv('UTF-8', 'SJIS', $utf8_string)));
34
35echo "\n-- Convert to UTF-8 --\n";
36echo "Expected UTF-8 encoded string in base64:\n";
37var_dump(bin2hex($utf8_string));
38echo "Converted Strings:\n";
39var_dump(bin2hex(iconv('SJIS', 'UTF-8', $sjis_string)));
40var_dump(bin2hex(iconv('EUC-JP', 'UTF-8', $euc_jp_string)));
41
42echo "Done";
43?>
44--EXPECT--
45*** Testing iconv() : basic functionality ***
46
47-- Convert to EUC-JP --
48Expected EUC-JP encoded string in base64:
49string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3"
50Converted Strings:
51string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3"
52string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3"
53
54-- Convert to SJIS --
55Expected SJIS encoded string in base64:
56string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142"
57Converted Strings:
58string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142"
59string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142"
60
61-- Convert to UTF-8 --
62Expected UTF-8 encoded string in base64:
63string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
64Converted Strings:
65string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
66string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
67Done
68