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