1--TEST-- 2GH-9535 (mb_strcut(): The behavior of mb_strcut in mbstring has been changed in PHP8.1) 3--EXTENSIONS-- 4mbstring 5--FILE-- 6<?php 7$encodings = [ 8 'BASE64', 9 'HTML-ENTITIES', 10 'Quoted-Printable', 11 'UTF-16', 12 'UTF-16BE', 13 'UTF-16LE', 14 'UTF-7', 15 'UTF7-IMAP', 16 'ISO-2022-JP-MS', 17 'GB18030', 18 'HZ', 19 'ISO-2022-KR', 20 'ISO-2022-JP-MOBILE#KDDI', 21 'CP50220', 22 'CP50221', 23 'CP50222', 24]; 25 26$input = '宛如繁星般宛如皎月般'; 27$bytes_length = 15; 28foreach($encodings as $encoding) { 29 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 30 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 31 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 32 echo $encoding.': '.$reconverted_str.PHP_EOL; 33} 34 35echo PHP_EOL; 36 37$input = '星のように月のように'; 38$bytes_length = 20; 39foreach($encodings as $encoding) { 40 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 41 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 42 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 43 echo $encoding.': '.$reconverted_str.PHP_EOL; 44} 45 46echo PHP_EOL; 47 48$input = 'あaいb'; 49$bytes_length = 10; 50foreach($encodings as $encoding) { 51 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 52 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 53 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 54 echo $encoding.': '.$reconverted_str.PHP_EOL; 55} 56 57echo PHP_EOL; 58 59$input = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; 60$bytes_length = 10; 61foreach($encodings as $encoding) { 62 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 63 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 64 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 65 echo $encoding.': '.$reconverted_str.PHP_EOL; 66} 67 68echo PHP_EOL; 69 70$input = '???'; 71$bytes_length = 2; 72foreach($encodings as $encoding) { 73 $converted_str = mb_convert_encoding($input, $encoding, mb_internal_encoding()); 74 $cut_str = mb_strcut($converted_str, 0, $bytes_length, $encoding); 75 $reconverted_str = mb_convert_encoding($cut_str, mb_internal_encoding(), $encoding); 76 echo $encoding.': '.$reconverted_str.PHP_EOL; 77} 78 79echo PHP_EOL; 80 81foreach($encodings as $encoding) { 82 var_dump(mb_strcut($input, 0, $bytes_length, $encoding)); 83} 84 85?> 86--EXPECTF-- 87BASE64: 宛如繁 88HTML-ENTITIES: 宛如 89Quoted-Printable: %s 90UTF-16: 宛如繁星般宛如 91UTF-16BE: 宛如繁星般宛如 92UTF-16LE: 宛如繁星般宛如 93UTF-7: 宛如繁星 94UTF7-IMAP: 宛如繁星 95ISO-2022-JP-MS: 宛如繁星 96GB18030: 宛如繁星般宛如 97HZ: 宛如繁星般 98ISO-2022-KR: 宛如繁星 99ISO-2022-JP-MOBILE#KDDI: 宛如繁星 100CP50220: 宛如繁星 101CP50221: 宛如繁星 102CP50222: 宛如繁星 103 104BASE64: 星のように 105HTML-ENTITIES: 星の 106Quoted-Printable: 星の 107UTF-16: 星のように月のように 108UTF-16BE: 星のように月のように 109UTF-16LE: 星のように月のように 110UTF-7: 星のように月 111UTF7-IMAP: 星のように月 112ISO-2022-JP-MS: 星のように月の 113GB18030: 星のように月のように 114HZ: 星のように月のよ 115ISO-2022-KR: 星のように月の 116ISO-2022-JP-MOBILE#KDDI: 星のように月の 117CP50220: 星のように月の 118CP50221: 星のように月の 119CP50222: 星のように月の 120 121BASE64: %s 122HTML-ENTITIES: あa& 123Quoted-Printable: あa 124UTF-16: あaいb 125UTF-16BE: あaいb 126UTF-16LE: あaいb 127UTF-7: あa 128UTF7-IMAP: あa 129ISO-2022-JP-MS: あa 130GB18030: あaいb 131HZ: あa 132ISO-2022-KR: あa 133ISO-2022-JP-MOBILE#KDDI: あa 134CP50220: あa 135CP50221: あa 136CP50222: あa 137 138BASE64: AAAAAA 139HTML-ENTITIES: AAAAAAAAAA 140Quoted-Printable: AAAAAAAAAA 141UTF-16: AAAAA 142UTF-16BE: AAAAA 143UTF-16LE: AAAAA 144UTF-7: AAAAAAAAAA 145UTF7-IMAP: AAAAAAAAAA 146ISO-2022-JP-MS: AAAAAAAAAA 147GB18030: AAAAAAAAAA 148HZ: AAAAAAAAAA 149ISO-2022-KR: AAAAAAAAAA 150ISO-2022-JP-MOBILE#KDDI: AAAAAAAAAA 151CP50220: AAAAAAAAAA 152CP50221: AAAAAAAAAA 153CP50222: AAAAAAAAAA 154 155BASE64:%s 156HTML-ENTITIES: ?? 157Quoted-Printable: ?? 158UTF-16: ? 159UTF-16BE: ? 160UTF-16LE: ? 161UTF-7: ?? 162UTF7-IMAP: ?? 163ISO-2022-JP-MS: ?? 164GB18030: ?? 165HZ: ?? 166ISO-2022-KR: ?? 167ISO-2022-JP-MOBILE#KDDI: ?? 168CP50220: ?? 169CP50221: ?? 170CP50222: ?? 171 172string(0) "" 173string(2) "??" 174string(2) "??" 175string(2) "??" 176string(2) "??" 177string(2) "??" 178string(2) "??" 179string(2) "??" 180string(2) "??" 181string(2) "??" 182string(2) "??" 183string(2) "??" 184string(2) "??" 185string(2) "??" 186string(2) "??" 187string(2) "??" 188