1--TEST--
2Test mb_strstr() function : basic functionality
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
10echo "*** Testing mb_strstr() : basic functionality ***\n";
11
12mb_internal_encoding('UTF-8');
13
14$string_ascii = 'abc def';
15//Japanese string in UTF-8
16$string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
17
18echo "\n-- ASCII string: needle exists --\n";
19var_dump(bin2hex(mb_strstr($string_ascii, 'd', false, 'ISO-8859-1')));
20var_dump(bin2hex(mb_strstr($string_ascii, 'd')));
21var_dump(bin2hex(mb_strstr($string_ascii, 'd', true)));
22
23
24echo "\n-- ASCII string: needle doesn't exist --\n";
25var_dump(mb_strstr($string_ascii, '123'));
26
27echo "\n-- Multibyte string: needle exists --\n";
28$needle1 = base64_decode('5pel5pys6Kqe');
29var_dump(bin2hex(mb_strstr($string_mb, $needle1)));
30var_dump(bin2hex(mb_strstr($string_mb, $needle1, false, 'utf-8')));
31var_dump(bin2hex(mb_strstr($string_mb, $needle1, true)));
32
33
34echo "\n-- Multibyte string: needle doesn't exist --\n";
35$needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
36var_dump(mb_strstr($string_mb, $needle2));
37
38?>
39--EXPECT--
40*** Testing mb_strstr() : basic functionality ***
41
42-- ASCII string: needle exists --
43string(6) "646566"
44string(6) "646566"
45string(8) "61626320"
46
47-- ASCII string: needle doesn't exist --
48bool(false)
49
50-- Multibyte string: needle exists --
51string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
52string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
53string(0) ""
54
55-- Multibyte string: needle doesn't exist --
56bool(false)
57