mb_substr_count_basic.phpt 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --TEST--
  2. Test mb_substr_count() function : basic functionality
  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. * Test Basic functionality of mb_substr_count
  16. */
  17. echo "*** Testing mb_substr_count() : basic functionality ***\n";
  18. $string_ascii = 'This is an English string. 0123456789.';
  19. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  20. $needle_mb1 = base64_decode('44CC');
  21. $needle_mb2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
  22. echo "\n-- ASCII String --\n";
  23. var_dump(mb_substr_count($string_ascii, 'is'));
  24. var_dump(mb_substr_count($string_ascii, 'hello, world'));
  25. echo "\n-- Multibyte String --\n";
  26. var_dump(mb_substr_count($string_mb, $needle_mb1));
  27. var_dump(mb_substr_count($string_mb, $needle_mb2));
  28. echo "Done";
  29. ?>
  30. --EXPECTF--
  31. *** Testing mb_substr_count() : basic functionality ***
  32. -- ASCII String --
  33. int(3)
  34. int(0)
  35. -- Multibyte String --
  36. int(2)
  37. int(0)
  38. Done