1--TEST--
2Test strtok() function : usage variations - with different token strings
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 different token strings
12*/
13
14echo "*** Testing strtok() : with different token strings ***\n";
15// initialize all required variables
16$str = 'this testcase test strtok() function ';
17
18// get an unset variable
19$unset_var = 'string_val';
20unset($unset_var);
21
22// declaring a class
23class sample  {
24  public function __toString() {
25  return "obj-ect";
26  }
27}
28
29// Defining resource
30$file_handle = fopen(__FILE__, 'r');
31
32// array with different values
33$values =  array (
34
35  // integer values
36  0,
37  1,
38  12345,
39  -2345,
40
41  // float values
42  10.5,
43  -10.5,
44  10.5e10,
45  10.6E-10,
46  .5,
47
48  // array values
49  array(),
50  array(0),
51  array(1),
52  array(1, 2),
53  array('color' => 'red', 'item' => 'pen'),
54
55  // boolean values
56  true,
57  false,
58  TRUE,
59  FALSE,
60
61  // objects
62  new sample(),
63
64  // empty string
65  "",
66  '',
67
68  // null vlaues
69  NULL,
70  null,
71
72  // undefined variable
73  $undefined_var,
74
75  // unset variable
76  $unset_var,
77
78  // resource
79  $file_handle
80);
81
82
83// loop through each element of the array and check the working of strtok()
84// when $token argument is supplied with different values
85
86echo "\n--- Testing strtok() by supplying different values for 'token' argument ---\n";
87$counter = 1;
88for($index = 0; $index < count($values); $index ++) {
89  echo "-- Iteration $counter --\n";
90  $token = $values [$index];
91
92  var_dump( strtok($str, $token) );
93
94  $counter ++;
95}
96
97// closing the resource
98fclose($file_handle);
99
100echo "Done\n";
101?>
102--EXPECTF--
103*** Testing strtok() : with different token strings ***
104
105Notice: Undefined variable: undefined_var in %s on line %d
106
107Notice: Undefined variable: unset_var in %s on line %d
108
109--- Testing strtok() by supplying different values for 'token' argument ---
110-- Iteration 1 --
111string(37) "this testcase test strtok() function "
112-- Iteration 2 --
113string(37) "this testcase test strtok() function "
114-- Iteration 3 --
115string(37) "this testcase test strtok() function "
116-- Iteration 4 --
117string(37) "this testcase test strtok() function "
118-- Iteration 5 --
119string(37) "this testcase test strtok() function "
120-- Iteration 6 --
121string(37) "this testcase test strtok() function "
122-- Iteration 7 --
123string(37) "this testcase test strtok() function "
124-- Iteration 8 --
125string(37) "this testcase test strtok() function "
126-- Iteration 9 --
127string(37) "this testcase test strtok() function "
128-- Iteration 10 --
129
130Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
131NULL
132-- Iteration 11 --
133
134Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
135NULL
136-- Iteration 12 --
137
138Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
139NULL
140-- Iteration 13 --
141
142Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
143NULL
144-- Iteration 14 --
145
146Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
147NULL
148-- Iteration 15 --
149string(37) "this testcase test strtok() function "
150-- Iteration 16 --
151string(37) "this testcase test strtok() function "
152-- Iteration 17 --
153string(37) "this testcase test strtok() function "
154-- Iteration 18 --
155string(37) "this testcase test strtok() function "
156-- Iteration 19 --
157string(4) "his "
158-- Iteration 20 --
159string(37) "this testcase test strtok() function "
160-- Iteration 21 --
161string(37) "this testcase test strtok() function "
162-- Iteration 22 --
163string(37) "this testcase test strtok() function "
164-- Iteration 23 --
165string(37) "this testcase test strtok() function "
166-- Iteration 24 --
167string(37) "this testcase test strtok() function "
168-- Iteration 25 --
169string(37) "this testcase test strtok() function "
170-- Iteration 26 --
171
172Warning: strtok() expects parameter 2 to be string, resource given in %s on line %d
173NULL
174Done
175