strcspn_variation5.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. --TEST--
  2. Test strcspn() function : usage variations - with heredoc strings with default start and len args
  3. --FILE--
  4. <?php
  5. /* Prototype : proto int strcspn(string str, string mask [, int start [, int len]])
  6. * Description: Finds length of initial segment consisting entirely of characters not found in mask.
  7. If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
  8. * Source code: ext/standard/string.c
  9. * Alias to functions: none
  10. */
  11. /*
  12. * Testing strcspn() : with different heredoc strings as str argument
  13. */
  14. echo "*** Testing strcspn() : with heredoc strings ***\n";
  15. // initialing required variables
  16. // defining different heredoc strings
  17. $empty_heredoc = <<<EOT
  18. EOT;
  19. $heredoc_with_newline = <<<EOT
  20. \n
  21. EOT;
  22. $heredoc_with_characters = <<<EOT
  23. first line of heredoc string
  24. second line of heredoc string
  25. third line of heredocstring
  26. EOT;
  27. $heredoc_with_newline_and_tabs = <<<EOT
  28. hello\tworld\nhello\nworld\n
  29. EOT;
  30. $heredoc_with_alphanumerics = <<<EOT
  31. hello123world456
  32. 1234hello\t1234
  33. EOT;
  34. $heredoc_with_embedded_nulls = <<<EOT
  35. hello\0world\0hello
  36. \0hello\0
  37. EOT;
  38. $heredoc_with_hexa_octal = <<<EOT
  39. hello\0\100\xaaworld\0hello
  40. \0hello\0
  41. EOT;
  42. $heredoc_strings = array(
  43. $empty_heredoc,
  44. $heredoc_with_newline,
  45. $heredoc_with_characters,
  46. $heredoc_with_newline_and_tabs,
  47. $heredoc_with_alphanumerics,
  48. $heredoc_with_embedded_nulls,
  49. $heredoc_with_hexa_octal
  50. );
  51. $mask = "fth12\ne67890\0\xaa\100o";
  52. // loop through each element of the array for str argument
  53. foreach($heredoc_strings as $str) {
  54. echo "\n-- Iteration with str value as \"$str\" --\n";
  55. var_dump( strcspn($str,$mask) ); // with default start and len values
  56. };
  57. echo "Done"
  58. ?>
  59. --EXPECTF--
  60. *** Testing strcspn() : with heredoc strings ***
  61. -- Iteration with str value as "" --
  62. int(0)
  63. -- Iteration with str value as "
  64. " --
  65. int(0)
  66. -- Iteration with str value as "first line of heredoc string
  67. second line of heredoc string
  68. third line of heredocstring" --
  69. int(0)
  70. -- Iteration with str value as "hello world
  71. hello
  72. world
  73. " --
  74. int(0)
  75. -- Iteration with str value as "hello123world456
  76. 1234hello 1234" --
  77. int(0)
  78. -- Iteration with str value as "hello%0world%0hello
  79. %0hello%0" --
  80. int(0)
  81. -- Iteration with str value as "hello%0@ªworld%0hello
  82. %0hello%0" --
  83. int(0)
  84. Done