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--EXPECTF-- 40*** Testing strtok() : with embedded nulls in the strings *** 41 42--- Iteration 1 --- 43bool(false) 44 45Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 46bool(false) 47 48Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 49bool(false) 50 51Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 52bool(false) 53 54Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 55bool(false) 56 57Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 58bool(false) 59 60--- Iteration 2 --- 61string(2) "\0" 62bool(false) 63bool(false) 64bool(false) 65bool(false) 66bool(false) 67 68--- Iteration 3 --- 69string(5) "hello" 70string(5) "world" 71bool(false) 72bool(false) 73bool(false) 74bool(false) 75 76--- Iteration 4 --- 77string(3) "hel" 78string(2) "lo" 79bool(false) 80bool(false) 81bool(false) 82bool(false) 83 84--- Iteration 5 --- 85string(5) "hello" 86bool(false) 87bool(false) 88bool(false) 89bool(false) 90bool(false) 91 92--- Iteration 6 --- 93string(11) "hello world" 94bool(false) 95 96Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 97bool(false) 98 99Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 100bool(false) 101 102Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 103bool(false) 104 105Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 106bool(false) 107 108--- Iteration 7 --- 109string(4) "\0he" 110string(5) "llo\0" 111bool(false) 112bool(false) 113bool(false) 114bool(false) 115 116--- Iteration 8 --- 117string(9) "hello\0\0" 118bool(false) 119bool(false) 120bool(false) 121bool(false) 122bool(false) 123Done 124