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--EXPECT--
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)
72bool(false)
73
74
75--- Iteration 2 ---
76string(1) "\"
77string(6) "hello\"
78string(7) " world\"
79bool(false)
80
81string(9) "\khello\k"
82string(7) "world\k"
83bool(false)
84bool(false)
85
86string(1) "\"
87string(6) "hello\"
88string(7) " world\"
89bool(false)
90
91string(5) "hello"
92string(6) " world"
93bool(false)
94bool(false)
95
96string(1) " "
97string(1) "r"
98bool(false)
99bool(false)
100
101
102--- Iteration 3 ---
103string(1) "/"
104string(6) "hello\"
105string(7) " world/"
106bool(false)
107
108string(8) "khello\k"
109string(5) "world"
110string(1) "k"
111bool(false)
112
113string(6) "hello\"
114string(6) " world"
115bool(false)
116bool(false)
117
118string(1) "/"
119string(5) "hello"
120string(7) " world/"
121bool(false)
122
123string(1) "/"
124string(1) " "
125string(1) "r"
126string(1) "/"
127
128
129--- Iteration 4 ---
130string(6) "/hello"
131string(7) "/ world"
132bool(false)
133bool(false)
134
135string(6) "hellok"
136string(5) "world"
137bool(false)
138bool(false)
139
140string(5) "hello"
141string(6) " world"
142bool(false)
143bool(false)
144
145string(6) "/hello"
146string(7) "/ world"
147bool(false)
148bool(false)
149
150string(1) "/"
151string(2) "/ "
152string(1) "r"
153bool(false)
154
155Done
156