1--TEST--
2Test strtok() function : usage variations - miscellaneous inputs
3--FILE--
4<?php
5/*
6 * Testing strtok() : with miscellaneous combinations of string and token
7*/
8
9echo "*** Testing strtok() : with miscellaneous inputs ***\n";
10
11// defining arrays for input strings and tokens
12$string_array = array(
13               "HELLO WORLD",
14               "hello world",
15               "_HELLO_WORLD_",
16               "/thello/t/wor/ttld",
17               "hel/lo/t/world",
18                       "one:$:two:!:three:#:four",
19               "\rhello/r/wor\rrld",
20                   chr(0),
21                       chr(0).chr(0),
22                       chr(0).'hello'.chr(0),
23                       'hello'.chr(0).'world'
24             );
25$token_array = array(
26              "wr",
27              "hello world",
28              "__",
29                      "t/",
30              '/t',
31              ":",
32              "\r",
33              "\0",
34              "\0",
35              "\0",
36              "\0",
37            );
38
39// loop through each element of the array and check the working of strtok()
40// when supplied with different string and token values
41
42$counter =1;
43foreach( $string_array as $string )  {
44  echo "\n--- Iteration $counter ---\n";
45  var_dump( strtok($string, $token_array[$counter-1]) );
46  for( $count = 1; $count <=5; $count++ )  {
47    var_dump( strtok($token_array[$counter-1]) );
48  }
49  $counter++;
50}
51
52
53echo "Done\n";
54?>
55--EXPECT--
56*** Testing strtok() : with miscellaneous inputs ***
57
58--- Iteration 1 ---
59string(11) "HELLO WORLD"
60bool(false)
61bool(false)
62bool(false)
63bool(false)
64bool(false)
65
66--- Iteration 2 ---
67bool(false)
68bool(false)
69bool(false)
70bool(false)
71bool(false)
72bool(false)
73
74--- Iteration 3 ---
75string(5) "HELLO"
76string(5) "WORLD"
77bool(false)
78bool(false)
79bool(false)
80bool(false)
81
82--- Iteration 4 ---
83string(5) "hello"
84string(3) "wor"
85string(2) "ld"
86bool(false)
87bool(false)
88bool(false)
89
90--- Iteration 5 ---
91string(3) "hel"
92string(2) "lo"
93string(5) "world"
94bool(false)
95bool(false)
96bool(false)
97
98--- Iteration 6 ---
99string(3) "one"
100string(1) "$"
101string(3) "two"
102string(1) "!"
103string(5) "three"
104string(1) "#"
105
106--- Iteration 7 ---
107string(11) "hello/r/wor"
108string(3) "rld"
109bool(false)
110bool(false)
111bool(false)
112bool(false)
113
114--- Iteration 8 ---
115bool(false)
116bool(false)
117bool(false)
118bool(false)
119bool(false)
120bool(false)
121
122--- Iteration 9 ---
123bool(false)
124bool(false)
125bool(false)
126bool(false)
127bool(false)
128bool(false)
129
130--- Iteration 10 ---
131string(5) "hello"
132bool(false)
133bool(false)
134bool(false)
135bool(false)
136bool(false)
137
138--- Iteration 11 ---
139string(5) "hello"
140string(5) "world"
141bool(false)
142bool(false)
143bool(false)
144bool(false)
145Done
146