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