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