mb_strrpos_basic.phpt 1.4 KB

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