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/* Prototype : int mb_stripos(string haystack, string needle [, int offset [, string encoding]]) 11 * Description: Finds position of first occurrence of a string within another, case insensitive 12 * Source code: ext/mbstring/mbstring.c 13 * Alias to functions: 14 */ 15 16/* 17 * Test how mb_stripos() behaves when passed different integers as $offset argument 18 * The character length of $string_ascii and $string_mb is the same, 19 * and the needle appears at the same positions in both strings 20 */ 21 22mb_internal_encoding('UTF-8'); 23 24echo "*** Testing mb_stripos() : usage variations ***\n"; 25 26$string_ascii = b'+Is an English string'; //21 chars 27$needle_ascii = b'G'; 28 29$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII='); //21 chars 30$needle_mb = base64_decode('44CC'); 31 32/* 33 * Loop through integers as multiples of ten for $offset argument 34 * mb_stripos should not be able to accept negative values as $offset. 35 * 60 is larger than *BYTE* count for $string_mb 36 */ 37for ($i = -10; $i <= 60; $i += 10) { 38 echo "\n**-- Offset is: $i --**\n"; 39 echo "-- ASCII String --\n"; 40 var_dump(mb_stripos($string_ascii, $needle_ascii, $i)); 41 echo "--Multibyte String --\n"; 42 var_dump(mb_stripos($string_mb, $needle_mb, $i, 'UTF-8')); 43} 44 45echo "Done"; 46?> 47 48--EXPECTF-- 49*** Testing mb_stripos() : usage variations *** 50 51**-- Offset is: -10 --** 52-- ASCII String -- 53 54Warning: mb_stripos(): Offset not contained in string in %s on line %d 55bool(false) 56--Multibyte String -- 57 58Warning: mb_stripos(): Offset not contained in string in %s on line %d 59bool(false) 60 61**-- Offset is: 0 --** 62-- ASCII String -- 63int(9) 64--Multibyte String -- 65int(9) 66 67**-- Offset is: 10 --** 68-- ASCII String -- 69int(20) 70--Multibyte String -- 71int(20) 72 73**-- Offset is: 20 --** 74-- ASCII String -- 75int(20) 76--Multibyte String -- 77int(20) 78 79**-- Offset is: 30 --** 80-- ASCII String -- 81 82Warning: mb_stripos(): Offset not contained in string in %s on line %d 83bool(false) 84--Multibyte String -- 85 86Warning: mb_stripos(): Offset not contained in string in %s on line %d 87bool(false) 88 89**-- Offset is: 40 --** 90-- ASCII String -- 91 92Warning: mb_stripos(): Offset not contained in string in %s on line %d 93bool(false) 94--Multibyte String -- 95 96Warning: mb_stripos(): Offset not contained in string in %s on line %d 97bool(false) 98 99**-- Offset is: 50 --** 100-- ASCII String -- 101 102Warning: mb_stripos(): Offset not contained in string in %s on line %d 103bool(false) 104--Multibyte String -- 105 106Warning: mb_stripos(): Offset not contained in string in %s on line %d 107bool(false) 108 109**-- Offset is: 60 --** 110-- ASCII String -- 111 112Warning: mb_stripos(): Offset not contained in string in %s on line %d 113bool(false) 114--Multibyte String -- 115 116Warning: mb_stripos(): Offset not contained in string in %s on line %d 117bool(false) 118Done 119 120