1--TEST-- 2Test strtok() function : usage variations - miscellaneous inputs 3--FILE-- 4<?php 5/* 6 * Testing strtok() : with miscellaneous combinations of string and token 7*/ 8 9echo "*** Testing strtok() : with miscellaneous inputs ***\n"; 10 11// defining arrays for input strings and tokens 12$string_array = array( 13 "HELLO WORLD", 14 "hello world", 15 "_HELLO_WORLD_", 16 "/thello/t/wor/ttld", 17 "hel/lo/t/world", 18 "one:$:two:!:three:#:four", 19 "\rhello/r/wor\rrld", 20 chr(0), 21 chr(0).chr(0), 22 chr(0).'hello'.chr(0), 23 'hello'.chr(0).'world' 24 ); 25$token_array = array( 26 "wr", 27 "hello world", 28 "__", 29 "t/", 30 '/t', 31 ":", 32 "\r", 33 "\0", 34 "\0", 35 "\0", 36 "\0", 37 ); 38 39// loop through each element of the array and check the working of strtok() 40// when supplied with different string and token values 41 42$counter =1; 43foreach( $string_array as $string ) { 44 echo "\n--- Iteration $counter ---\n"; 45 var_dump( strtok($string, $token_array[$counter-1]) ); 46 for( $count = 1; $count <=5; $count++ ) { 47 var_dump( strtok($token_array[$counter-1]) ); 48 } 49 $counter++; 50} 51 52 53echo "Done\n"; 54?> 55--EXPECTF-- 56*** Testing strtok() : with miscellaneous inputs *** 57 58--- Iteration 1 --- 59string(11) "HELLO WORLD" 60bool(false) 61bool(false) 62bool(false) 63bool(false) 64bool(false) 65 66--- Iteration 2 --- 67bool(false) 68 69Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 70bool(false) 71 72Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 73bool(false) 74 75Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 76bool(false) 77 78Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 79bool(false) 80 81Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 82bool(false) 83 84--- Iteration 3 --- 85string(5) "HELLO" 86string(5) "WORLD" 87bool(false) 88bool(false) 89bool(false) 90bool(false) 91 92--- Iteration 4 --- 93string(5) "hello" 94string(3) "wor" 95string(2) "ld" 96bool(false) 97bool(false) 98bool(false) 99 100--- Iteration 5 --- 101string(3) "hel" 102string(2) "lo" 103string(5) "world" 104bool(false) 105bool(false) 106bool(false) 107 108--- Iteration 6 --- 109string(3) "one" 110string(1) "$" 111string(3) "two" 112string(1) "!" 113string(5) "three" 114string(1) "#" 115 116--- Iteration 7 --- 117string(11) "hello/r/wor" 118string(3) "rld" 119bool(false) 120bool(false) 121bool(false) 122bool(false) 123 124--- Iteration 8 --- 125bool(false) 126 127Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 128bool(false) 129 130Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 131bool(false) 132 133Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 134bool(false) 135 136Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 137bool(false) 138 139Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 140bool(false) 141 142--- Iteration 9 --- 143bool(false) 144 145Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 146bool(false) 147 148Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 149bool(false) 150 151Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 152bool(false) 153 154Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 155bool(false) 156 157Warning: strtok(): Both arguments must be provided when starting tokenization in %s on line %d 158bool(false) 159 160--- Iteration 10 --- 161string(5) "hello" 162bool(false) 163bool(false) 164bool(false) 165bool(false) 166bool(false) 167 168--- Iteration 11 --- 169string(5) "hello" 170string(5) "world" 171bool(false) 172bool(false) 173bool(false) 174bool(false) 175Done 176