mb_strrchr_variation6.phpt 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. --TEST--
  2. Test mb_strrchr() function : variation - case sensitivity
  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. //ascii
  18. $string_ascii = b'abcdef';
  19. $needle_ascii_upper = b"BCD";
  20. $needle_ascii_mixed = b"bCd";
  21. $needle_ascii_lower = b"bcd";
  22. //Greek string in lower case UTF-8
  23. $string_mb = base64_decode('zrHOss6zzrTOtc62zrfOuM65zrrOu868zr3Ovs6/z4DPgc+Dz4TPhc+Gz4fPiM+J');
  24. $needle_mb_upper = base64_decode('zpzOnc6ezp8=');
  25. $needle_mb_lower = base64_decode('zrzOvc6+zr8=');
  26. $needle_mb_mixed = base64_decode('zpzOnc6+zr8=');
  27. echo "-- Ascii data --\n";
  28. // needle should be found
  29. var_dump(bin2hex(mb_strrchr($string_ascii, $needle_ascii_lower)));
  30. // no needle should be found
  31. var_dump(mb_strrchr($string_ascii, $needle_ascii_upper));
  32. var_dump(mb_strrchr($string_ascii, $needle_ascii_mixed));
  33. echo "-- mb data in utf-8 --\n";
  34. // needle should be found
  35. $res = mb_strrchr($string_mb, $needle_mb_lower, false);
  36. if ($res !== false) {
  37. var_dump(bin2hex($res));
  38. }
  39. else {
  40. echo "nothing found!\n";
  41. }
  42. // no needle should be found
  43. var_dump(mb_strrchr($string_mb, $needle_mb_upper));
  44. var_dump(mb_strrchr($string_mb, $needle_mb_mixed));
  45. ?>
  46. ===DONE===
  47. --EXPECT--
  48. *** Testing mb_strrchr() : variation ***
  49. -- Ascii data --
  50. string(10) "6263646566"
  51. bool(false)
  52. bool(false)
  53. -- mb data in utf-8 --
  54. string(52) "cebccebdcebecebfcf80cf81cf83cf84cf85cf86cf87cf88cf89"
  55. bool(false)
  56. bool(false)
  57. ===DONE===