1--TEST-- 2Test mb_strstr() function : variation - multiple needles 3--SKIPIF-- 4<?php 5extension_loaded('mbstring') or die('skip'); 6function_exists('mb_strstr') or die("skip mb_strstr() is not available in this build"); 7?> 8--FILE-- 9<?php 10/* Prototype : string mb_strstr(string haystack, string needle[, bool part[, string encoding]]) 11 * Description: Finds first occurrence of a string within another 12 * Source code: ext/mbstring/mbstring.c 13 * Alias to functions: 14 */ 15 16echo "*** Testing mb_strstr() : variation ***\n"; 17 18mb_internal_encoding('UTF-8'); 19 20//with repeated needles 21$string_ascii = 'abcdef zbcdyx'; 22$needle_ascii = "bcd"; 23 24//Japanese string in UTF-8 with repeated needles 25$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OIMzTvvJXvvJbml6XmnKzoqp7jg4bjgq3jgrnjg4g='); 26$needle_mb = base64_decode('6Kqe44OG44Kt'); 27 28echo "-- Ascii data --\n"; 29var_dump(bin2hex(mb_strstr($string_ascii, $needle_ascii, false))); 30var_dump(bin2hex(mb_strstr($string_ascii, $needle_ascii, true))); 31 32echo "-- mb data in utf-8 --\n"; 33$res = mb_strstr($string_mb, $needle_mb, false); 34if ($res !== false) { 35 var_dump(bin2hex($res)); 36} 37else { 38 echo "nothing found!\n"; 39} 40$res = mb_strstr($string_mb, $needle_mb, true); 41if ($res !== false) { 42 var_dump(bin2hex($res)); 43} 44else { 45 echo "nothing found!\n"; 46} 47 48 49?> 50===DONE=== 51--EXPECT-- 52*** Testing mb_strstr() : variation *** 53-- Ascii data -- 54string(24) "6263646566207a6263647978" 55string(2) "61" 56-- mb data in utf-8 -- 57string(88) "e8aa9ee38386e382ade382b9e383883334efbc95efbc96e697a5e69cace8aa9ee38386e382ade382b9e38388" 58string(12) "e697a5e69cac" 59===DONE=== 60