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