1--TEST-- 2Test mb_convert_encoding() function : array functionality 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_convert_encoding') or die("skip mb_convert_encoding() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* 11 * Test basic functionality of mb_convert_encoding() 12 */ 13 14echo "*** Testing mb_convert_encoding() : array functionality ***\n"; 15 16//All strings are the same when displayed in their respective encodings 17$sjis_string[] = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=='); 18$sjis_string[] = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg=='); 19$jis_string[] = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=='); 20$jis_string[] = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=='); 21$euc_jp_string[] = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=='); 22$euc_jp_string[] = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=='); 23$utf8_string[] = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 24$utf8_string[] = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 25 26 27function base64_encode_array($input) { 28 foreach ($input as $var) { 29 $ret[] = base64_encode($var); 30 } 31 return $ret; 32} 33 34echo "\n-- Convert to JIS --\n"; 35echo "JIS encoded string in base64:\n"; 36var_dump(base64_encode_array($jis_string)); 37echo "Converted Strings:\n"; 38var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'JIS', 'SJIS'))); 39var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'JIS', 'EUC-JP'))); 40var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'JIS', 'UTF-8'))); 41 42echo "\n-- Convert to EUC-JP --\n"; 43echo "EUC-JP encoded string in base64:\n"; 44var_dump(base64_encode_array($euc_jp_string)); 45echo "Converted Strings:\n"; 46var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'EUC-JP', 'SJIS'))); 47var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'EUC-JP', 'JIS'))); 48var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'EUC-JP', 'UTF-8'))); 49 50echo "\n-- Convert to SJIS --\n"; 51echo "SJIS encoded string in base64:\n"; 52var_dump(base64_encode_array($sjis_string)); 53echo "Converted Strings:\n"; 54var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'SJIS', 'JIS'))); 55var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'SJIS', 'EUC-JP'))); 56var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'SJIS', 'UTF-8'))); 57 58echo "\n-- Convert to UTF-8 --\n"; 59echo "UTF-8 encoded string in base64:\n"; 60var_dump(base64_encode_array($utf8_string)); 61echo "Converted Strings:\n"; 62var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'UTF-8', 'SJIS'))); 63var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'UTF-8', 'JIS'))); 64var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'UTF-8', 'EUC-JP'))); 65 66echo "Done"; 67?> 68--EXPECT-- 69*** Testing mb_convert_encoding() : array functionality *** 70 71-- Convert to JIS -- 72JIS encoded string in base64: 73array(2) { 74 [0]=> 75 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 76 [1]=> 77 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 78} 79Converted Strings: 80array(2) { 81 [0]=> 82 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 83 [1]=> 84 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 85} 86array(2) { 87 [0]=> 88 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 89 [1]=> 90 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 91} 92array(2) { 93 [0]=> 94 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 95 [1]=> 96 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 97} 98 99-- Convert to EUC-JP -- 100EUC-JP encoded string in base64: 101array(2) { 102 [0]=> 103 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 104 [1]=> 105 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 106} 107Converted Strings: 108array(2) { 109 [0]=> 110 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 111 [1]=> 112 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 113} 114array(2) { 115 [0]=> 116 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 117 [1]=> 118 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 119} 120array(2) { 121 [0]=> 122 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 123 [1]=> 124 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 125} 126 127-- Convert to SJIS -- 128SJIS encoded string in base64: 129array(2) { 130 [0]=> 131 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 132 [1]=> 133 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 134} 135Converted Strings: 136array(2) { 137 [0]=> 138 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 139 [1]=> 140 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 141} 142array(2) { 143 [0]=> 144 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 145 [1]=> 146 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 147} 148array(2) { 149 [0]=> 150 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 151 [1]=> 152 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 153} 154 155-- Convert to UTF-8 -- 156UTF-8 encoded string in base64: 157array(2) { 158 [0]=> 159 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 160 [1]=> 161 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 162} 163Converted Strings: 164array(2) { 165 [0]=> 166 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 167 [1]=> 168 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 169} 170array(2) { 171 [0]=> 172 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 173 [1]=> 174 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 175} 176array(2) { 177 [0]=> 178 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 179 [1]=> 180 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 181} 182Done 183