1--TEST-- 2iconv_substr() 3--SKIPIF-- 4<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?> 5--INI-- 6iconv.internal_charset=ISO-8859-1 7--FILE-- 8<?php 9function hexdump($str) { 10 $len = strlen($str); 11 for ($i = 0; $i < $len; ++$i) { 12 printf("%02x", ord($str[$i])); 13 } 14 print "\n"; 15} 16 17function foo($str, $offset, $len, $charset) { 18 hexdump(substr($str, $offset, $len)); 19 hexdump(iconv_substr($str, $offset, $len, $charset)); 20} 21 22function bar($str, $offset, $len = false) { 23 if (is_bool($len)) { 24 var_dump(substr($str, $offset)); 25 var_dump(iconv_substr($str, $offset)); 26 } else { 27 var_dump(substr($str, $offset, $len)); 28 var_dump(iconv_substr($str, $offset, $len)); 29 } 30} 31 32foo("abcdefghijklmnopqrstuvwxyz", 5, 7, "ASCII"); 33foo("��������������������������", 5, 7, "EUC-JP"); 34bar("This is a test", 100000); 35bar("This is a test", 0, 100000); 36bar("This is a test", -3); 37bar("This is a test", -3, null); 38bar("This is a test", 0, -9); 39bar("This is a test", 0, -100000); 40bar("This is a test", -9, -100000); 41var_dump(iconv("ISO-2022-JP", "EUC-JP", iconv_substr(iconv("EUC-JP", "ISO-2022-JP", "����ˤ��� ISO-2022-JP"), 3, 8, "ISO-2022-JP"))); 42?> 43--EXPECT-- 44666768696a6b6c 45666768696a6b6c 46a6a4a8a4aaa4ab 47a4aba4ada4afa4b1a4b3a4b5a4b7 48string(0) "" 49string(0) "" 50string(14) "This is a test" 51string(14) "This is a test" 52string(3) "est" 53string(3) "est" 54string(3) "est" 55string(3) "est" 56string(5) "This " 57string(5) "This " 58string(0) "" 59string(0) "" 60string(0) "" 61string(0) "" 62string(10) "���� ISO-2" 63