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-- overlapped substrings --\n";
13var_dump( substr_count("abcabcabcabcabc", "abca") );
14var_dump( substr_count("abcabcabcabcabc", "abca", 2) );
15
16echo "\n-- complex strings containing other than 7-bit chars --\n";
17$str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255);
18var_dump(substr_count($str, chr(128)));
19var_dump(substr_count($str, chr(255)));
20var_dump(substr_count($str, chr(256)));
21
22echo "\n-- heredoc string --\n";
23$string = <<<EOD
24abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
25abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
26acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
27acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
28abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
29abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
30abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
31abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789
32EOD;
33var_dump(substr_count($string, "abcd"));
34var_dump(substr_count($string, "1234"));
35
36echo "\n-- heredoc null string --\n";
37$str = <<<EOD
38EOD;
39var_dump(substr_count($str, "\0"));
40var_dump(substr_count($str, "\x000"));
41var_dump(substr_count($str, "0"));
42
43echo "Done\n";
44
45?>
46--EXPECT--
47*** Testing possible variations ***
48-- 3rd or 4th arg as string --
49int(1)
50int(1)
51
52-- overlapped substrings --
53int(2)
54int(2)
55
56-- complex strings containing other than 7-bit chars --
57int(2)
58int(2)
59int(1)
60
61-- heredoc string --
62int(14)
63int(16)
64
65-- heredoc null string --
66int(0)
67int(0)
68int(0)
69Done
70