summaryrefslogtreecommitdiff
path: root/ext/standard/tests/strings/strtok_variation6.phpt
blob: 7008e3b67ed6f4649b6cede39167ae0f5b33c7e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
--TEST--
Test strtok() function : usage variations - invalid escape sequences as tokens
--FILE--
<?php
/* Prototype  : string strtok ( str $str, str $token )
 * Description: splits a string (str) into smaller strings (tokens), with each token being delimited by any character from token
 * Source code: ext/standard/string.c
*/

/*
 * Testing strtok() : with invalid escape sequences in token
*/

echo "*** Testing strtok() : with invalid escape sequences in token ***\n";

// defining arrays for input strings and tokens
$string_array = array(
 		       "khellok worldk",
 		       "\khello\k world\k",
 		       "/khello\k world/k",
 		       "/hellok/ world"
 		     );
$token_array = array(
		       "k",
		       "/ ",
		       "/k",
		       "\k",
		       "\\\\\\\k\h\\e\l\o\w\r\l\d"
 		    );

// loop through each element of the array and check the working of strtok()
// when supplied with different string and token values

$counter =1;
foreach( $string_array as $string )  {
  echo "\n--- Iteration $counter ---\n";
  foreach( $token_array as $token )  {
    var_dump( strtok($string, $token) );
    for( $count = 1; $count <=3; $count++ )  {
      var_dump( strtok($token) );
    }
    echo "\n";
  }
  $counter++;
}


echo "Done\n";
?>
--EXPECTF--
*** Testing strtok() : with invalid escape sequences in token ***

--- Iteration 1 ---
string(5) "hello"
string(6) " world"
bool(false)
bool(false)

string(7) "khellok"
string(6) "worldk"
bool(false)
bool(false)

string(5) "hello"
string(6) " world"
bool(false)
bool(false)

string(5) "hello"
string(6) " world"
bool(false)
bool(false)

string(1) " "
string(1) "r"
bool(false)
bool(false)


--- Iteration 2 ---
string(1) "\"
string(6) "hello\"
string(7) " world\"
bool(false)

string(9) "\khello\k"
string(7) "world\k"
bool(false)
bool(false)

string(1) "\"
string(6) "hello\"
string(7) " world\"
bool(false)

string(5) "hello"
string(6) " world"
bool(false)
bool(false)

string(1) " "
string(1) "r"
bool(false)
bool(false)


--- Iteration 3 ---
string(1) "/"
string(6) "hello\"
string(7) " world/"
bool(false)

string(8) "khello\k"
string(5) "world"
string(1) "k"
bool(false)

string(6) "hello\"
string(6) " world"
bool(false)
bool(false)

string(1) "/"
string(5) "hello"
string(7) " world/"
bool(false)

string(1) "/"
string(1) " "
string(1) "r"
string(1) "/"


--- Iteration 4 ---
string(6) "/hello"
string(7) "/ world"
bool(false)
bool(false)

string(6) "hellok"
string(5) "world"
bool(false)
bool(false)

string(5) "hello"
string(6) " world"
bool(false)
bool(false)

string(6) "/hello"
string(7) "/ world"
bool(false)
bool(false)

string(1) "/"
string(2) "/ "
string(1) "r"
bool(false)

Done