mb_substr_count_variation4.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --TEST--
  2. Test mb_substr_count() function : variation - pass a $needle that overlaps in $haystack
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_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. * Pass mb_substr_count() a $needle that overlaps in $haystack and see whether
  16. * it counts only the first occurrence or all other occurrences regardless whether they
  17. * were part of previous match
  18. */
  19. echo "*** Testing mb_substr_count() : usage variations ***\n";
  20. echo "\n-- ASCII String --\n";
  21. $string_ascii = b'abcabcabc';
  22. var_dump(mb_substr_count($string_ascii, b'abcabc')); //needle overlaps in haystack
  23. echo "\n-- Multibyte String --\n";
  24. $string_mb = base64_decode('5pel5pys6Kqe5pel5pys6Kqe5pel5pys6Kqe');
  25. $needle_mb = base64_decode('5pel5pys6Kqe5pel5pys6Kqe');
  26. var_dump(mb_substr_count($string_mb, $needle_mb, 'utf-8'));
  27. echo "Done";
  28. ?>
  29. --EXPECTF--
  30. *** Testing mb_substr_count() : usage variations ***
  31. -- ASCII String --
  32. int(1)
  33. -- Multibyte String --
  34. int(1)
  35. Done