1--TEST--
2Test mb_substr_count() function : variation - pass a $needle that overlaps in $haystack
3--SKIPIF--
4<?php
5extension_loaded('mbstring') or die('skip');
6function_exists('mb_substr_count') or die("skip mb_substr_count() is not available in this build");
7?>
8--FILE--
9<?php
10/* Prototype  : int mb_substr_count(string $haystack, string $needle [, string $encoding])
11 * Description: Count the number of substring occurrences
12 * Source code: ext/mbstring/mbstring.c
13 */
14
15/*
16 * Pass mb_substr_count() a $needle that overlaps in $haystack and see whether
17 * it counts only the first occurrence or all other occurrences regardless whether they
18 * were part of previous match
19 */
20
21echo "*** Testing mb_substr_count() : usage variations ***\n";
22
23
24echo "\n-- ASCII String --\n";
25$string_ascii = b'abcabcabc';
26var_dump(mb_substr_count($string_ascii, b'abcabc')); //needle overlaps in haystack
27
28echo "\n-- Multibyte String --\n";
29$string_mb = base64_decode('5pel5pys6Kqe5pel5pys6Kqe5pel5pys6Kqe');
30$needle_mb = base64_decode('5pel5pys6Kqe5pel5pys6Kqe');
31var_dump(mb_substr_count($string_mb, $needle_mb, 'utf-8'));
32
33
34echo "Done";
35?>
36--EXPECTF--
37*** Testing mb_substr_count() : usage variations ***
38
39-- ASCII String --
40int(1)
41
42-- Multibyte String --
43int(1)
44Done