1--TEST--
2Test substr_count() function (variation - 1)
3--FILE--
4<?php
5
6echo "\n*** Testing possible variations ***\n";
7echo "-- 3rd or 4th arg as string --\n";
8$str = "this is a string";
9var_dump( substr_count($str, "t", "5") );
10var_dump( substr_count($str, "t", "5", "10") );
11
12echo "\n-- 3rd or 4th arg as NULL --\n";
13var_dump( substr_count($str, "I", NULL) );
14var_dump( substr_count($str, "i", NULL, 10) );
15
16echo "\n-- overlapped substrings --\n";
17var_dump( substr_count("abcabcabcabcabc", "abca") );
18var_dump( substr_count("abcabcabcabcabc", "abca", 2) );
19
20echo "\n-- complex strings containing other than 7-bit chars --\n";
21$str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255);
22var_dump(substr_count($str, chr(128)));
23var_dump(substr_count($str, chr(255)));
24var_dump(substr_count($str, chr(256)));
25
26echo "\n-- heredoc string --\n";
27$string = <<<EOD
28abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
29abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
30acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
31acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
32abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
33abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
34abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
35abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
36EOD;
37var_dump(substr_count($string, "abcd"));
38var_dump(substr_count($string, "1234"));
39
40echo "\n-- heredoc null string --\n";
41$str = <<<EOD
42EOD;
43var_dump(substr_count($str, "\0"));
44var_dump(substr_count($str, "\x000"));
45var_dump(substr_count($str, "0"));
46
47echo "Done\n";
48
49?>
50--EXPECT--
51*** Testing possible variations ***
52-- 3rd or 4th arg as string --
53int(1)
54int(1)
55
56-- 3rd or 4th arg as NULL --
57int(0)
58int(2)
59
60-- overlapped substrings --
61int(2)
62int(2)
63
64-- complex strings containing other than 7-bit chars --
65int(2)
66int(2)
67int(1)
68
69-- heredoc string --
70int(14)
71int(16)
72
73-- heredoc null string --
74int(0)
75int(0)
76int(0)
77Done
78