1--TEST-- 2Test output of mb_strcut for text encodings which use escape sequences 3--EXTENSIONS-- 4mbstring 5--FILE-- 6<?php 7 8$encodings = [ 9 'JIS', 10 'ISO-2022-JP', 11 'ISO-2022-JP-2004', 12]; 13 14$input = '宛如繁星般宛如皎月般'; 15$bytes_length = 15; 16foreach($encodings as $encoding) { 17 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 18 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 19 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 20 echo $encoding.': '.$reconverted_str.PHP_EOL; 21} 22 23echo PHP_EOL; 24 25$input = '星のように月のように'; 26$bytes_length = 20; 27foreach($encodings as $encoding) { 28 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 29 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 30 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 31 echo $encoding.': '.$reconverted_str.PHP_EOL; 32} 33 34echo PHP_EOL; 35 36$input = 'あaいb'; 37$bytes_length = 10; 38foreach($encodings as $encoding) { 39 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 40 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 41 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 42 echo $encoding.': '.$reconverted_str.PHP_EOL; 43} 44 45echo PHP_EOL; 46 47$input = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; 48$bytes_length = 10; 49foreach($encodings as $encoding) { 50 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 51 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 52 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 53 echo $encoding.': '.$reconverted_str.PHP_EOL; 54} 55 56echo PHP_EOL; 57 58$input = '???'; 59$bytes_length = 2; 60foreach($encodings as $encoding) { 61 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 62 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 63 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 64 echo $encoding.': '.$reconverted_str.PHP_EOL; 65} 66 67echo PHP_EOL; 68 69foreach($encodings as $encoding) { 70 var_dump(mb_strcut($input, 0, $bytes_length, $encoding)); 71} 72 73?> 74--EXPECTF-- 75JIS: 宛如繁星 76ISO-2022-JP: 宛如繁星 77ISO-2022-JP-2004: 宛如繁星 78 79JIS: 星のように月の 80ISO-2022-JP: 星のように月の 81ISO-2022-JP-2004: 星のように月 82 83JIS: あa 84ISO-2022-JP: あa 85ISO-2022-JP-2004: あa 86 87JIS: AAAAAAAAAA 88ISO-2022-JP: AAAAAAAAAA 89ISO-2022-JP-2004: AAAAAAAAAA 90 91JIS: ?? 92ISO-2022-JP: ?? 93ISO-2022-JP-2004: ?? 94 95string(2) "??" 96string(2) "??" 97string(2) "??" 98