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