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