mb_strrchr_variation5.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Test mb_strrchr() function : variation - multiple needles
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_strrchr') or die("skip mb_strrchr() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : string mb_strrchr(string haystack, string needle[, bool part[, string encoding]])
  11. * Description: Finds the last occurrence of a character in a string within another
  12. * Source code: ext/mbstring/mbstring.c
  13. * Alias to functions:
  14. */
  15. echo "*** Testing mb_strrchr() : variation ***\n";
  16. mb_internal_encoding('UTF-8');
  17. //with repeated needles
  18. $string_ascii = b'abcdef zbcdyx';
  19. $needle_ascii = b"bcd";
  20. //Japanese string in UTF-8 with repeated needles
  21. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OIMzTvvJXvvJbml6XmnKzoqp7jg4bjgq3jgrnjg4g=');
  22. $needle_mb = base64_decode('6Kqe44OG44Kt');
  23. echo "-- Ascii data --\n";
  24. var_dump(bin2hex(mb_strrchr($string_ascii, $needle_ascii, false)));
  25. var_dump(bin2hex(mb_strrchr($string_ascii, $needle_ascii, true)));
  26. echo "-- mb data in utf-8 --\n";
  27. $res = mb_strrchr($string_mb, $needle_mb, false);
  28. if ($res !== false) {
  29. var_dump(bin2hex($res));
  30. }
  31. else {
  32. echo "nothing found!\n";
  33. }
  34. $res = mb_strrchr($string_mb, $needle_mb, true);
  35. if ($res !== false) {
  36. var_dump(bin2hex($res));
  37. }
  38. else {
  39. echo "nothing found!\n";
  40. }
  41. ?>
  42. ===DONE===
  43. --EXPECT--
  44. *** Testing mb_strrchr() : variation ***
  45. -- Ascii data --
  46. string(10) "6263647978"
  47. string(16) "616263646566207a"
  48. -- mb data in utf-8 --
  49. string(30) "e8aa9ee38386e382ade382b9e38388"
  50. string(70) "e697a5e69cace8aa9ee38386e382ade382b9e383883334efbc95efbc96e697a5e69cac"
  51. ===DONE===