1--TEST-- 2Test mb_convert_encoding() function : Circular references 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() : Circular references ***\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$tmp = &$sjis_string; 25$sjis_string[] = $tmp; 26 27$jis_string[] = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=='); 28$jis_string[] = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg=='); 29$tmp = &$jis_string; 30$jis_string[] = $tmp; 31 32$euc_jp_string[] = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=='); 33$euc_jp_string[] = base64_decode('xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow=='); 34$tmp = &$euc_jp_string; 35$euc_jp_string[] = $tmp; 36 37$utf8_string[] = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 38$utf8_string[] = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); 39$tmp = &$utf8_string; 40$utf8_string[] = $tmp; 41 42 43function base64_encode_array($input) { 44 foreach ($input as $var) { 45 if (is_scalar($var)) 46 $ret[] = base64_encode($var); 47 } 48 return $ret; 49} 50 51echo "\n-- Convert to JIS --\n"; 52echo "JIS encoded string in base64:\n"; 53var_dump(base64_encode_array($jis_string)); 54echo "Converted Strings:\n"; 55var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'JIS', 'SJIS'))); 56var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'JIS', 'EUC-JP'))); 57var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'JIS', 'UTF-8'))); 58 59echo "\n-- Convert to EUC-JP --\n"; 60echo "EUC-JP encoded string in base64:\n"; 61var_dump(base64_encode_array($euc_jp_string)); 62echo "Converted Strings:\n"; 63var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'EUC-JP', 'SJIS'))); 64var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'EUC-JP', 'JIS'))); 65var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'EUC-JP', 'UTF-8'))); 66 67echo "\n-- Convert to SJIS --\n"; 68echo "SJIS encoded string in base64:\n"; 69var_dump(base64_encode_array($sjis_string)); 70echo "Converted Strings:\n"; 71var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'SJIS', 'JIS'))); 72var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'SJIS', 'EUC-JP'))); 73var_dump(base64_encode_array(mb_convert_encoding($utf8_string, 'SJIS', 'UTF-8'))); 74 75echo "\n-- Convert to UTF-8 --\n"; 76echo "UTF-8 encoded string in base64:\n"; 77var_dump(base64_encode_array($utf8_string)); 78echo "Converted Strings:\n"; 79var_dump(base64_encode_array(mb_convert_encoding($sjis_string, 'UTF-8', 'SJIS'))); 80var_dump(base64_encode_array(mb_convert_encoding($jis_string, 'UTF-8', 'JIS'))); 81var_dump(base64_encode_array(mb_convert_encoding($euc_jp_string, 'UTF-8', 'EUC-JP'))); 82 83echo "Done"; 84?> 85--EXPECTF-- 86*** Testing mb_convert_encoding() : Circular references *** 87 88-- Convert to JIS -- 89JIS encoded string in base64: 90array(2) { 91 [0]=> 92 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 93 [1]=> 94 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 95} 96Converted Strings: 97 98Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 99array(2) { 100 [0]=> 101 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 102 [1]=> 103 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 104} 105 106Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 107array(2) { 108 [0]=> 109 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 110 [1]=> 111 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 112} 113 114Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 115array(2) { 116 [0]=> 117 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 118 [1]=> 119 string(68) "GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==" 120} 121 122-- Convert to EUC-JP -- 123EUC-JP encoded string in base64: 124array(2) { 125 [0]=> 126 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 127 [1]=> 128 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 129} 130Converted Strings: 131 132Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 133array(2) { 134 [0]=> 135 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 136 [1]=> 137 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 138} 139 140Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 141array(2) { 142 [0]=> 143 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 144 [1]=> 145 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 146} 147 148Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 149array(2) { 150 [0]=> 151 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 152 [1]=> 153 string(52) "xvzL3LjspcalraW5pcikx6S5oaMwMTIzNKO1o7ajt6O4o7mhow==" 154} 155 156-- Convert to SJIS -- 157SJIS encoded string in base64: 158array(2) { 159 [0]=> 160 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 161 [1]=> 162 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 163} 164Converted Strings: 165 166Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 167array(2) { 168 [0]=> 169 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 170 [1]=> 171 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 172} 173 174Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 175array(2) { 176 [0]=> 177 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 178 [1]=> 179 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 180} 181 182Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 183array(2) { 184 [0]=> 185 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 186 [1]=> 187 string(52) "k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==" 188} 189 190-- Convert to UTF-8 -- 191UTF-8 encoded string in base64: 192array(2) { 193 [0]=> 194 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 195 [1]=> 196 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 197} 198Converted Strings: 199 200Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 201array(2) { 202 [0]=> 203 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 204 [1]=> 205 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 206} 207 208Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 209array(2) { 210 [0]=> 211 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 212 [1]=> 213 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 214} 215 216Warning: mb_convert_encoding(): Cannot convert recursively referenced values in %s on line %d 217array(2) { 218 [0]=> 219 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 220 [1]=> 221 string(72) "5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=" 222} 223Done 224