mb_strrchr_basic.phpt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. Test mb_strrchr() function : basic functionality
  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() : basic functionality ***\n";
  16. mb_internal_encoding('UTF-8');
  17. $string_ascii = b'abc def';
  18. //Japanese string in UTF-8
  19. $string_mb = base64_decode('5pel5pys6Kqe44OG44Kt44K544OI44Gn44GZ44CCMDEyMzTvvJXvvJbvvJfvvJjvvJnjgII=');
  20. echo "\n-- ASCII string: needle exists --\n";
  21. var_dump(bin2hex(mb_strrchr($string_ascii, b'd', false, 'ISO-8859-1')));
  22. var_dump(bin2hex(mb_strrchr($string_ascii, b'd')));
  23. var_dump(bin2hex(mb_strrchr($string_ascii, b'd', true)));
  24. echo "\n-- ASCII string: needle doesn't exist --\n";
  25. var_dump(mb_strrchr($string_ascii, b'123'));
  26. echo "\n-- Multibyte string: needle exists --\n";
  27. $needle1 = base64_decode('5pel5pys6Kqe');
  28. var_dump(bin2hex(mb_strrchr($string_mb, $needle1)));
  29. var_dump(bin2hex(mb_strrchr($string_mb, $needle1, false, 'utf-8')));
  30. var_dump(bin2hex(mb_strrchr($string_mb, $needle1, true)));
  31. echo "\n-- Multibyte string: needle doesn't exist --\n";
  32. $needle2 = base64_decode('44GT44KT44Gr44Gh44Gv44CB5LiW55WM');
  33. var_dump(mb_strrchr($string_mb, $needle2));
  34. ?>
  35. ===DONE===
  36. --EXPECT--
  37. *** Testing mb_strrchr() : basic functionality ***
  38. -- ASCII string: needle exists --
  39. string(6) "646566"
  40. string(6) "646566"
  41. string(8) "61626320"
  42. -- ASCII string: needle doesn't exist --
  43. bool(false)
  44. -- Multibyte string: needle exists --
  45. string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
  46. string(106) "e697a5e69cace8aa9ee38386e382ade382b9e38388e381a7e38199e380823031323334efbc95efbc96efbc97efbc98efbc99e38082"
  47. string(0) ""
  48. -- Multibyte string: needle doesn't exist --
  49. bool(false)
  50. ===DONE===