mb_strpos_basic.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. Test mb_strpos() function : basic functionality
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_strpos') or die("skip mb_strpos() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : int mb_strpos(string $haystack, string $needle [, int $offset [, string $encoding]])
  11. * Description: Find position of first occurrence of a string within another
  12. * Source code: ext/mbstring/mbstring.c
  13. */
  14. /*
  15. * Test basic functionality of mb_strpos with ASCII and multibyte characters
  16. */
  17. echo "*** Testing mb_strpos() : basic functionality***\n";
  18. mb_internal_encoding('UTF-8');
  19. $string_ascii = b'abc def';
  20. //Japanese string in UTF-8
  21. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  22. echo "\n-- ASCII string 1 --\n";
  23. var_dump(mb_strpos($string_ascii, b'd', 2, 'ISO-8859-1'));
  24. echo "\n-- ASCII string 2 --\n";
  25. var_dump(mb_strpos($string_ascii, '123'));
  26. echo "\n-- Multibyte string 1 --\n";
  27. $needle1 = base64_decode('5pel5pys6Kqe');
  28. var_dump(mb_strpos($string_mb, $needle1));
  29. echo "\n-- Multibyte string 2 --\n";
  30. $needle2 = base64_decode("44GT44KT44Gr44Gh44Gv44CB5LiW55WM");
  31. var_dump(mb_strpos($string_mb, $needle2));
  32. echo "Done";
  33. ?>
  34. --EXPECT--
  35. *** Testing mb_strpos() : basic functionality***
  36. -- ASCII string 1 --
  37. int(4)
  38. -- ASCII string 2 --
  39. bool(false)
  40. -- Multibyte string 1 --
  41. int(0)
  42. -- Multibyte string 2 --
  43. bool(false)
  44. Done