strripos_basic2.phpt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. --TEST--
  2. Test strripos() function : basic functionality - with all arguments
  3. --FILE--
  4. <?php
  5. /* Prototype : int strripos ( string $haystack, string $needle [, int $offset] );
  6. * Description: Find position of last occurrence of a case-insensitive 'needle' in a 'haystack'
  7. * Source code: ext/standard/string.c
  8. */
  9. echo "*** Testing strripos() function: basic functionality ***\n";
  10. $heredoc_str = <<<EOD
  11. Hello, World
  12. EOD;
  13. echo "\n-- regular string for haystack & needle, with various offsets --\n";
  14. var_dump( strripos("Hello, World", "HeLLo", 0) );
  15. var_dump( strripos("Hello, World", 'Hello', 1) );
  16. var_dump( strripos('Hello, World', 'world', 1) );
  17. var_dump( strripos('Hello, World', "WorLD", 5) );
  18. echo "\n-- heredoc string for haystack & needle, with various offsets --\n";
  19. var_dump( strripos($heredoc_str, "Hello, WORLD", 0) );
  20. var_dump( strripos($heredoc_str, 'HelLo', 0) );
  21. var_dump( strripos($heredoc_str, 'HeLLo', 1) );
  22. var_dump( strripos($heredoc_str, $heredoc_str, 0) );
  23. var_dump( strripos($heredoc_str, $heredoc_str, 1) );
  24. echo "\n-- various +ve offsets --\n";
  25. var_dump( strripos("Hello, World", "O", 3) );
  26. var_dump( strripos("Hello, World", "O", 6) );
  27. var_dump( strripos("Hello, World", "O", 10) );
  28. echo "\n-- various -ve offsets --\n";
  29. var_dump( strripos("Hello, World", "O", -1) );
  30. var_dump( strripos("Hello, World", "O", -5) );
  31. var_dump( strripos("Hello, World", "O", -9) );
  32. ?>
  33. ===DONE===
  34. --EXPECT--
  35. *** Testing strripos() function: basic functionality ***
  36. -- regular string for haystack & needle, with various offsets --
  37. int(0)
  38. bool(false)
  39. int(7)
  40. int(7)
  41. -- heredoc string for haystack & needle, with various offsets --
  42. int(0)
  43. int(0)
  44. bool(false)
  45. int(0)
  46. bool(false)
  47. -- various +ve offsets --
  48. int(8)
  49. int(8)
  50. bool(false)
  51. -- various -ve offsets --
  52. int(8)
  53. int(4)
  54. bool(false)
  55. ===DONE===