1--TEST--
2Test strtok() function : usage variations - with embedded nulls in the strings
3--FILE--
4<?php
5/*
6 * Testing strtok() : with embedded nulls in the strings
7*/
8
9echo "*** Testing strtok() : with embedded nulls in the strings ***\n";
10
11// defining varous strings with embedded nulls
12$strings_with_nulls = array(
13                   "\0",
14                   '\0',
15                           "hello\0world",
16                           "\0hel\0lo",
17                           "hello\0",
18                           "\0\0hello\tworld\0\0",
19                           "\\0he\0llo\\0",
20                           'hello\0\0'
21                           );
22
23// loop through each element of the array and check the working of strtok()
24// when supplied with different string values
25
26$counter = 1;
27foreach( $strings_with_nulls as $string )  {
28  echo "\n--- Iteration $counter ---\n";
29  var_dump( strtok($string, "\0") );
30  for($count = 1; $count <= 5; $count++)  {
31    var_dump( strtok("\0") );
32  }
33  $counter++;
34}
35
36
37echo "Done\n";
38?>
39--EXPECT--
40*** Testing strtok() : with embedded nulls in the strings ***
41
42--- Iteration 1 ---
43bool(false)
44bool(false)
45bool(false)
46bool(false)
47bool(false)
48bool(false)
49
50--- Iteration 2 ---
51string(2) "\0"
52bool(false)
53bool(false)
54bool(false)
55bool(false)
56bool(false)
57
58--- Iteration 3 ---
59string(5) "hello"
60string(5) "world"
61bool(false)
62bool(false)
63bool(false)
64bool(false)
65
66--- Iteration 4 ---
67string(3) "hel"
68string(2) "lo"
69bool(false)
70bool(false)
71bool(false)
72bool(false)
73
74--- Iteration 5 ---
75string(5) "hello"
76bool(false)
77bool(false)
78bool(false)
79bool(false)
80bool(false)
81
82--- Iteration 6 ---
83string(11) "hello	world"
84bool(false)
85bool(false)
86bool(false)
87bool(false)
88bool(false)
89
90--- Iteration 7 ---
91string(4) "\0he"
92string(5) "llo\0"
93bool(false)
94bool(false)
95bool(false)
96bool(false)
97
98--- Iteration 8 ---
99string(9) "hello\0\0"
100bool(false)
101bool(false)
102bool(false)
103bool(false)
104bool(false)
105Done
106