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 var_dump(base64_encode($a)); 35 echo "--Multibyte String --\n"; 36 $b = mb_substr($string_mb, $i, 4, 'UTF-8'); 37 if (strlen($a) == mb_strlen($b, 'UTF-8')) { // should return same length 38 var_dump(base64_encode($b)); 39 } else { 40 echo "Difference in length of ASCII string and multibyte string\n"; 41 } 42 43} 44 45echo "Done"; 46?> 47--EXPECT-- 48*** Testing mb_substr() : usage variations *** 49 50**-- Offset is: -60 --** 51-- ASCII String -- 52string(8) "K0lzIA==" 53--Multibyte String -- 54string(16) "5pel5pys6Kqe44OG" 55 56**-- Offset is: -50 --** 57-- ASCII String -- 58string(8) "K0lzIA==" 59--Multibyte String -- 60string(16) "5pel5pys6Kqe44OG" 61 62**-- Offset is: -40 --** 63-- ASCII String -- 64string(8) "K0lzIA==" 65--Multibyte String -- 66string(16) "5pel5pys6Kqe44OG" 67 68**-- Offset is: -30 --** 69-- ASCII String -- 70string(8) "K0lzIA==" 71--Multibyte String -- 72string(16) "5pel5pys6Kqe44OG" 73 74**-- Offset is: -20 --** 75-- ASCII String -- 76string(8) "SXMgYQ==" 77--Multibyte String -- 78string(16) "5pys6Kqe44OG44Kt" 79 80**-- Offset is: -10 --** 81-- ASCII String -- 82string(8) "aXNoIA==" 83--Multibyte String -- 84string(8) "MTIzNA==" 85 86**-- Offset is: 0 --** 87-- ASCII String -- 88string(8) "K0lzIA==" 89--Multibyte String -- 90string(16) "5pel5pys6Kqe44OG" 91 92**-- Offset is: 10 --** 93-- ASCII String -- 94string(8) "bGlzaA==" 95--Multibyte String -- 96string(8) "MDEyMw==" 97 98**-- Offset is: 20 --** 99-- ASCII String -- 100string(4) "Zw==" 101--Multibyte String -- 102string(4) "44CC" 103 104**-- Offset is: 30 --** 105-- ASCII String -- 106string(0) "" 107--Multibyte String -- 108string(0) "" 109 110**-- Offset is: 40 --** 111-- ASCII String -- 112string(0) "" 113--Multibyte String -- 114string(0) "" 115 116**-- Offset is: 50 --** 117-- ASCII String -- 118string(0) "" 119--Multibyte String -- 120string(0) "" 121 122**-- Offset is: 60 --** 123-- ASCII String -- 124string(0) "" 125--Multibyte String -- 126string(0) "" 127Done 128