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/* Prototype : string iconv(string in_charset, string out_charset, string str) 11 * Description: Returns converted string in desired encoding 12 * Source code: ext/iconv/iconv.c 13 */ 14 15/* 16 * Test basic functionality of iconv() 17 */ 18 19echo "*** Testing iconv() : basic functionality ***\n"; 20 21//All strings are the same when displayed in their respective encodings 22$sjis_string = base64_decode(b'k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=='); 23$euc_jp_string = base64_decode(b'xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=='); 24$utf8_string = base64_decode(b'5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 25 26echo "\n-- Convert to EUC-JP --\n"; 27echo "Expected EUC-JP encoded string in base64:\n"; 28var_dump(bin2hex($euc_jp_string)); 29echo "Converted Strings:\n"; 30var_dump(bin2hex(iconv('SJIS', 'EUC-JP', $sjis_string ))); 31var_dump(bin2hex(iconv('UTF-8', 'EUC-JP', $utf8_string))); 32 33echo "\n-- Convert to SJIS --\n"; 34echo "Expected SJIS encoded string in base64:\n"; 35var_dump(bin2hex($sjis_string)); 36echo "Converted Strings:\n"; 37var_dump(bin2hex(iconv('EUC-JP', 'SJIS', $euc_jp_string))); 38var_dump(bin2hex(iconv('UTF-8', 'SJIS', $utf8_string))); 39 40echo "\n-- Convert to UTF-8 --\n"; 41echo "Expected UTF-8 encoded string in base64:\n"; 42var_dump(bin2hex($utf8_string)); 43echo "Converted Strings:\n"; 44var_dump(bin2hex(iconv('SJIS', 'UTF-8', $sjis_string))); 45var_dump(bin2hex(iconv('EUC-JP', 'UTF-8', $euc_jp_string))); 46 47echo "Done"; 48?> 49--EXPECT-- 50*** Testing iconv() : basic functionality *** 51 52-- Convert to EUC-JP -- 53Expected EUC-JP encoded string in base64: 54string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3" 55Converted Strings: 56string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3" 57string(74) "c6fccbdcb8eca5c6a5ada5b9a5c8a4c7a4b9a1a33031323334a3b5a3b6a3b7a3b8a3b9a1a3" 58 59-- Convert to SJIS -- 60Expected SJIS encoded string in base64: 61string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142" 62Converted Strings: 63string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142" 64string(74) "93fa967b8cea8365834c8358836782c582b781423031323334825482558256825782588142" 65 66-- Convert to UTF-8 -- 67Expected UTF-8 encoded string in base64: 68string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082" 69Converted Strings: 70string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082" 71string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082" 72Done