1--TEST-- 2Test mb_stripos() function : usage variations - Pass different integers as $offset argument 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_stripos') or die("skip mb_stripos() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* 11 * Test how mb_stripos() behaves when passed different integers as $offset argument 12 * The character length of $string_ascii and $string_mb is the same, 13 * and the needle appears at the same positions in both strings 14 */ 15 16mb_internal_encoding('UTF-8'); 17 18echo "*** Testing mb_stripos() : usage variations ***\n"; 19 20$string_ascii = '+Is an English string'; //21 chars 21$needle_ascii = 'G'; 22 23$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars 24$needle_mb = base64_decode('44CC'); 25 26/* 27 * Loop through integers as multiples of ten for $offset argument 28 * mb_stripos should not be able to accept negative values as $offset. 29 * 60 is larger than *BYTE* count for $string_mb 30 */ 31for ($i = -30; $i <= 60; $i += 10) { 32 echo "\n**-- Offset is: $i --**\n"; 33 echo "-- ASCII String --\n"; 34 try { 35 var_dump(mb_stripos($string_ascii, $needle_ascii, $i)); 36 } catch (\ValueError $e) { 37 echo $e->getMessage() . \PHP_EOL; 38 } 39 echo "--Multibyte String --\n"; 40 try { 41 var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8')); 42 } catch (\ValueError $e) { 43 echo $e->getMessage() . \PHP_EOL; 44 } 45} 46 47?> 48--EXPECT-- 49*** Testing mb_stripos() : usage variations *** 50 51**-- Offset is: -30 --** 52-- ASCII String -- 53mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 54--Multibyte String -- 55mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 56 57**-- Offset is: -20 --** 58-- ASCII String -- 59int(9) 60--Multibyte String -- 61int(9) 62 63**-- Offset is: -10 --** 64-- ASCII String -- 65int(20) 66--Multibyte String -- 67int(20) 68 69**-- Offset is: 0 --** 70-- ASCII String -- 71int(9) 72--Multibyte String -- 73int(9) 74 75**-- Offset is: 10 --** 76-- ASCII String -- 77int(20) 78--Multibyte String -- 79int(20) 80 81**-- Offset is: 20 --** 82-- ASCII String -- 83int(20) 84--Multibyte String -- 85int(20) 86 87**-- Offset is: 30 --** 88-- ASCII String -- 89mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 90--Multibyte String -- 91mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 92 93**-- Offset is: 40 --** 94-- ASCII String -- 95mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 96--Multibyte String -- 97mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 98 99**-- Offset is: 50 --** 100-- ASCII String -- 101mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 102--Multibyte String -- 103mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 104 105**-- Offset is: 60 --** 106-- ASCII String -- 107mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 108--Multibyte String -- 109mb_stripos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) 110