1--TEST--
2Test strtok() function : usage variations - invalid escape sequences as tokens
3--FILE--
4<?php
5/*
6 * Testing strtok() : with invalid escape sequences in token
7*/
8
9echo "*** Testing strtok() : with invalid escape sequences in token ***\n";
10
11// defining arrays for input strings and tokens
12$string_array = array(
13               "khellok worldk",
14               "\khello\k world\k",
15               "/khello\k world/k",
16               "/hellok/ world"
17             );
18$token_array = array(
19               "k",
20               "/ ",
21               "/k",
22               "\k",
23               "\\\\\\\k\h\\e\l\o\w\r\l\d"
24            );
25
26// loop through each element of the array and check the working of strtok()
27// when supplied with different string and token values
28
29$counter =1;
30foreach( $string_array as $string )  {
31  echo "\n--- Iteration $counter ---\n";
32  foreach( $token_array as $token )  {
33    var_dump( strtok($string, $token) );
34    for( $count = 1; $count <=3; $count++ )  {
35      var_dump( strtok($token) );
36    }
37    echo "\n";
38  }
39  $counter++;
40}
41
42
43echo "Done\n";
44?>
45--EXPECTF--
46*** Testing strtok() : with invalid escape sequences in token ***
47
48--- Iteration 1 ---
49string(5) "hello"
50string(6) " world"
51bool(false)
52bool(false)
53
54string(7) "khellok"
55string(6) "worldk"
56bool(false)
57bool(false)
58
59string(5) "hello"
60string(6) " world"
61bool(false)
62bool(false)
63
64string(5) "hello"
65string(6) " world"
66bool(false)
67bool(false)
68
69string(1) " "
70string(1) "r"
71bool(false)
72
73Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
74bool(false)
75
76
77--- Iteration 2 ---
78string(1) "\"
79string(6) "hello\"
80string(7) " world\"
81bool(false)
82
83string(9) "\khello\k"
84string(7) "world\k"
85bool(false)
86bool(false)
87
88string(1) "\"
89string(6) "hello\"
90string(7) " world\"
91bool(false)
92
93string(5) "hello"
94string(6) " world"
95bool(false)
96
97Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
98bool(false)
99
100string(1) " "
101string(1) "r"
102bool(false)
103
104Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
105bool(false)
106
107
108--- Iteration 3 ---
109string(1) "/"
110string(6) "hello\"
111string(7) " world/"
112bool(false)
113
114string(8) "khello\k"
115string(5) "world"
116string(1) "k"
117bool(false)
118
119string(6) "hello\"
120string(6) " world"
121bool(false)
122
123Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d
124bool(false)
125
126string(1) "/"
127string(5) "hello"
128string(7) " world/"
129bool(false)
130
131string(1) "/"
132string(1) " "
133string(1) "r"
134string(1) "/"
135
136
137--- Iteration 4 ---
138string(6) "/hello"
139string(7) "/ world"
140bool(false)
141bool(false)
142
143string(6) "hellok"
144string(5) "world"
145bool(false)
146bool(false)
147
148string(5) "hello"
149string(6) " world"
150bool(false)
151bool(false)
152
153string(6) "/hello"
154string(7) "/ world"
155bool(false)
156bool(false)
157
158string(1) "/"
159string(2) "/ "
160string(1) "r"
161bool(false)
162
163Done
164