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