1--TEST-- 2Test mb_substr() function : usage variations - pass different integers to $start arg 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_substr') or die("skip mb_substr() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* 11 * Test how mb_substr() behaves when passed a range of integers as $start argument 12 */ 13 14echo "*** Testing mb_substr() : usage variations ***\n"; 15 16mb_internal_encoding('UTF-8'); 17 18$string_ascii = '+Is an English string'; //21 chars 19 20$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars 21 22/* 23 * Loop through integers as multiples of ten for $offset argument 24 * 60 is larger than *BYTE* count for $string_mb 25 */ 26for ($i = -60; $i <= 60; $i += 10) { 27 if (@$a || @$b) { 28 $a = null; 29 $b = null; 30 } 31 echo "\n**-- Offset is: $i --**\n"; 32 echo "-- ASCII String --\n"; 33 $a = mb_substr($string_ascii, $i, 4); 34 if ($a !== false) { 35 var_dump(bin2hex($a)); 36 } 37 else { 38 var_dump($a); 39 } 40 echo "--Multibyte String --\n"; 41 $b = mb_substr($string_mb, $i, 4, 'UTF-8'); 42 if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length 43 var_dump(bin2hex($b)); 44 } else { 45 echo "Difference in length of ASCII string and multibyte string\n"; 46 } 47 48} 49 50echo "Done"; 51?> 52--EXPECT-- 53*** Testing mb_substr() : usage variations *** 54 55**-- Offset is: -60 --** 56-- ASCII String -- 57string(8) "2b497320" 58--Multibyte String -- 59string(24) "e697a5e69cace8aa9ee38386" 60 61**-- Offset is: -50 --** 62-- ASCII String -- 63string(8) "2b497320" 64--Multibyte String -- 65string(24) "e697a5e69cace8aa9ee38386" 66 67**-- Offset is: -40 --** 68-- ASCII String -- 69string(8) "2b497320" 70--Multibyte String -- 71string(24) "e697a5e69cace8aa9ee38386" 72 73**-- Offset is: -30 --** 74-- ASCII String -- 75string(8) "2b497320" 76--Multibyte String -- 77string(24) "e697a5e69cace8aa9ee38386" 78 79**-- Offset is: -20 --** 80-- ASCII String -- 81string(8) "49732061" 82--Multibyte String -- 83string(24) "e69cace8aa9ee38386e382ad" 84 85**-- Offset is: -10 --** 86-- ASCII String -- 87string(8) "69736820" 88--Multibyte String -- 89string(8) "31323334" 90 91**-- Offset is: 0 --** 92-- ASCII String -- 93string(8) "2b497320" 94--Multibyte String -- 95string(24) "e697a5e69cace8aa9ee38386" 96 97**-- Offset is: 10 --** 98-- ASCII String -- 99string(8) "6c697368" 100--Multibyte String -- 101string(8) "30313233" 102 103**-- Offset is: 20 --** 104-- ASCII String -- 105string(2) "67" 106--Multibyte String -- 107string(6) "e38082" 108 109**-- Offset is: 30 --** 110-- ASCII String -- 111string(0) "" 112--Multibyte String -- 113string(0) "" 114 115**-- Offset is: 40 --** 116-- ASCII String -- 117string(0) "" 118--Multibyte String -- 119string(0) "" 120 121**-- Offset is: 50 --** 122-- ASCII String -- 123string(0) "" 124--Multibyte String -- 125string(0) "" 126 127**-- Offset is: 60 --** 128-- ASCII String -- 129string(0) "" 130--Multibyte String -- 131string(0) "" 132Done 133