bug43841.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. --TEST--
  2. Test mb_strrpos() function : mb_strrpos offset is byte count for negative values
  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 that mb_strrpos offset is byte count for negative values (should be character count)
  16. */
  17. $offsets = array(-25, -24, -13, -12);
  18. $string_mb =
  19. base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvv
  20. JfvvJjvvJnjgII=');
  21. $needle = base64_decode('44CC');
  22. foreach ($offsets as $i) {
  23. echo "\n-- Offset is $i --\n";
  24. echo "Multibyte String:\n";
  25. var_dump( mb_strrpos($string_mb, $needle, $i, 'UTF-8') );
  26. echo "ASCII String:\n";
  27. echo "mb_strrpos:\n";
  28. var_dump(mb_strrpos(b'This is na English ta', b'a', $i));
  29. echo "strrpos:\n";
  30. var_dump(strrpos(b'This is na English ta', b'a', $i));
  31. }
  32. ?>
  33. --EXPECTF--
  34. -- Offset is -25 --
  35. Multibyte String:
  36. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  37. bool(false)
  38. ASCII String:
  39. mb_strrpos:
  40. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  41. bool(false)
  42. strrpos:
  43. Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
  44. bool(false)
  45. -- Offset is -24 --
  46. Multibyte String:
  47. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  48. bool(false)
  49. ASCII String:
  50. mb_strrpos:
  51. Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
  52. bool(false)
  53. strrpos:
  54. Warning: strrpos(): Offset is greater than the length of haystack string in %s on line %d
  55. bool(false)
  56. -- Offset is -13 --
  57. Multibyte String:
  58. bool(false)
  59. ASCII String:
  60. mb_strrpos:
  61. bool(false)
  62. strrpos:
  63. bool(false)
  64. -- Offset is -12 --
  65. Multibyte String:
  66. int(9)
  67. ASCII String:
  68. mb_strrpos:
  69. int(9)
  70. strrpos:
  71. int(9)