mb_stristr_variation5.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. Test mb_stristr() function : usage variation - multiple needles
  3. --SKIPIF--
  4. <?php
  5. extension_loaded('mbstring') or die('skip');
  6. function_exists('mb_stristr') or die("skip mb_stristr() is not available in this build");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Prototype : string mb_stristr(string haystack, string needle[, bool part[, string encoding]])
  11. * Description: Finds first occurrence of a string within another, case insensitive
  12. * Source code: ext/mbstring/mbstring.c
  13. * Alias to functions:
  14. */
  15. echo "*** Testing mb_stristr() : basic functionality ***\n";
  16. mb_internal_encoding('UTF-8');
  17. //ascii mixed case, multiple needles
  18. $string_ascii = b'abcDef zBcDyx';
  19. $needle_ascii_upper = b"BCD";
  20. $needle_ascii_mixed = b"bCd";
  21. $needle_ascii_lower = b"bcd";
  22. //Greek string in mixed case UTF-8 with multiple needles
  23. $string_mb = base64_decode('zrrOu868zr3Ovs6fzqDOoSDOus67zpzOnc6+zr/OoA==');
  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 "\n-- ASCII string: needle exists --\n";
  28. var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_upper, false)));
  29. var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_upper, true)));
  30. var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_lower, false)));
  31. var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_lower, true)));
  32. var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_mixed, false)));
  33. var_dump(bin2hex(mb_stristr($string_ascii, $needle_ascii_mixed, true)));
  34. echo "\n-- Multibyte string: needle exists --\n";
  35. var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_upper, false)));
  36. var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_upper, true)));
  37. var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_lower, false)));
  38. var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_lower, true)));
  39. var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_mixed, false)));
  40. var_dump(bin2hex(mb_stristr($string_mb, $needle_mb_mixed, true)));
  41. ?>
  42. ===DONE===
  43. --EXPECT--
  44. *** Testing mb_stristr() : basic functionality ***
  45. -- ASCII string: needle exists --
  46. string(24) "6263446566207a4263447978"
  47. string(2) "61"
  48. string(24) "6263446566207a4263447978"
  49. string(2) "61"
  50. string(24) "6263446566207a4263447978"
  51. string(2) "61"
  52. -- Multibyte string: needle exists --
  53. string(54) "cebccebdcebece9fcea0cea120cebacebbce9cce9dcebecebfcea0"
  54. string(8) "cebacebb"
  55. string(54) "cebccebdcebece9fcea0cea120cebacebbce9cce9dcebecebfcea0"
  56. string(8) "cebacebb"
  57. string(54) "cebccebdcebece9fcea0cea120cebacebbce9cce9dcebecebfcea0"
  58. string(8) "cebacebb"
  59. ===DONE===