strcspn_variation6.phpt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. --TEST--
  2. Test strcspn() function : usage variations - with heredoc strings, varying mask & default start and len args
  3. --FILE--
  4. <?php
  5. /*
  6. * Testing strcspn() : with heredoc string, varying mask and default start and len arguments
  7. */
  8. echo "*** Testing strcspn() : with different mask strings ***\n";
  9. // initialing required variables
  10. // defining different heredoc strings
  11. $empty_heredoc = <<<EOT
  12. EOT;
  13. $heredoc_with_newline = <<<EOT
  14. \n
  15. EOT;
  16. $heredoc_with_characters = <<<EOT
  17. first line of heredoc string
  18. second line of heredoc string
  19. third line of heredocstring
  20. EOT;
  21. $heredoc_with_newline_and_tabs = <<<EOT
  22. hello\tworld\nhello\nworld\n
  23. EOT;
  24. $heredoc_with_alphanumerics = <<<EOT
  25. hello123world456
  26. 1234hello\t1234
  27. EOT;
  28. $heredoc_with_embedded_nulls = <<<EOT
  29. hello\0world\0hello
  30. \0hello\0
  31. EOT;
  32. $heredoc_with_hexa_octal = <<<EOT
  33. hello\0\100\xaaworld\0hello
  34. \0hello\0
  35. EOT;
  36. $heredoc_strings = array(
  37. $empty_heredoc,
  38. $heredoc_with_newline,
  39. $heredoc_with_characters,
  40. $heredoc_with_newline_and_tabs,
  41. $heredoc_with_alphanumerics,
  42. $heredoc_with_embedded_nulls,
  43. $heredoc_with_hexa_octal
  44. );
  45. // defining array of mask strings
  46. $mask_array = array(
  47. "",
  48. '',
  49. "\n\trsti \l",
  50. '\n\trsti \l',
  51. "\t",
  52. "t\ ",
  53. '\t',
  54. "\t\ ",
  55. " \t",
  56. "\t\i\100\xaa"
  57. );
  58. // loop through each element of the arrays for string and mask arguments
  59. $count = 1;
  60. foreach($heredoc_strings as $str) {
  61. echo "\n-- Iteration $count --\n";
  62. foreach($mask_array as $mask) {
  63. var_dump( strcspn($str,$mask) ); // with default start and len value
  64. }
  65. $count++;
  66. }
  67. echo "Done"
  68. ?>
  69. --EXPECT--
  70. *** Testing strcspn() : with different mask strings ***
  71. -- Iteration 1 --
  72. int(0)
  73. int(0)
  74. int(0)
  75. int(0)
  76. int(0)
  77. int(0)
  78. int(0)
  79. int(0)
  80. int(0)
  81. int(0)
  82. -- Iteration 2 --
  83. int(2)
  84. int(2)
  85. int(0)
  86. int(2)
  87. int(2)
  88. int(2)
  89. int(2)
  90. int(2)
  91. int(2)
  92. int(2)
  93. -- Iteration 3 --
  94. int(86)
  95. int(86)
  96. int(1)
  97. int(1)
  98. int(86)
  99. int(4)
  100. int(4)
  101. int(5)
  102. int(5)
  103. int(1)
  104. -- Iteration 4 --
  105. int(24)
  106. int(24)
  107. int(2)
  108. int(2)
  109. int(5)
  110. int(24)
  111. int(24)
  112. int(5)
  113. int(5)
  114. int(5)
  115. -- Iteration 5 --
  116. int(31)
  117. int(31)
  118. int(2)
  119. int(2)
  120. int(26)
  121. int(31)
  122. int(31)
  123. int(26)
  124. int(26)
  125. int(26)
  126. -- Iteration 6 --
  127. int(5)
  128. int(5)
  129. int(2)
  130. int(2)
  131. int(25)
  132. int(25)
  133. int(25)
  134. int(25)
  135. int(25)
  136. int(25)
  137. -- Iteration 7 --
  138. int(5)
  139. int(5)
  140. int(2)
  141. int(2)
  142. int(27)
  143. int(27)
  144. int(27)
  145. int(27)
  146. int(27)
  147. int(6)
  148. Done