Annotation of embedaddon/php/ext/standard/tests/strings/strtok_variation2.phpt, revision 1.1.1.2
1.1 misho 1: --TEST--
2: Test 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:
14: echo "*** 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';
20: unset($unset_var);
21:
22: // declaring a class
23: class 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()
1.1.1.2 ! misho 84: // when $token argument is supplied with different values
1.1 misho 85:
86: echo "\n--- Testing strtok() by supplying different values for 'token' argument ---\n";
87: $counter = 1;
88: for($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
98: fclose($file_handle);
99:
100: echo "Done\n";
101: ?>
102: --EXPECTF--
103: *** Testing strtok() : with different token strings ***
104:
105: Notice: Undefined variable: undefined_var in %s on line %d
106:
107: Notice: Undefined variable: unset_var in %s on line %d
108:
109: --- Testing strtok() by supplying different values for 'token' argument ---
110: -- Iteration 1 --
111: string(37) "this testcase test strtok() function "
112: -- Iteration 2 --
113: string(37) "this testcase test strtok() function "
114: -- Iteration 3 --
115: string(37) "this testcase test strtok() function "
116: -- Iteration 4 --
117: string(37) "this testcase test strtok() function "
118: -- Iteration 5 --
119: string(37) "this testcase test strtok() function "
120: -- Iteration 6 --
121: string(37) "this testcase test strtok() function "
122: -- Iteration 7 --
123: string(37) "this testcase test strtok() function "
124: -- Iteration 8 --
125: string(37) "this testcase test strtok() function "
126: -- Iteration 9 --
127: string(37) "this testcase test strtok() function "
128: -- Iteration 10 --
129:
130: Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
131: NULL
132: -- Iteration 11 --
133:
134: Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
135: NULL
136: -- Iteration 12 --
137:
138: Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
139: NULL
140: -- Iteration 13 --
141:
142: Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
143: NULL
144: -- Iteration 14 --
145:
146: Warning: strtok() expects parameter 2 to be string, array given in %s on line %d
147: NULL
148: -- Iteration 15 --
149: string(37) "this testcase test strtok() function "
150: -- Iteration 16 --
151: string(37) "this testcase test strtok() function "
152: -- Iteration 17 --
153: string(37) "this testcase test strtok() function "
154: -- Iteration 18 --
155: string(37) "this testcase test strtok() function "
156: -- Iteration 19 --
157: string(4) "his "
158: -- Iteration 20 --
159: string(37) "this testcase test strtok() function "
160: -- Iteration 21 --
161: string(37) "this testcase test strtok() function "
162: -- Iteration 22 --
163: string(37) "this testcase test strtok() function "
164: -- Iteration 23 --
165: string(37) "this testcase test strtok() function "
166: -- Iteration 24 --
167: string(37) "this testcase test strtok() function "
168: -- Iteration 25 --
169: string(37) "this testcase test strtok() function "
170: -- Iteration 26 --
171:
172: Warning: strtok() expects parameter 2 to be string, resource given in %s on line %d
173: NULL
174: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>