1--TEST-- 2Test strtok() function : usage variations - modifying the input string while tokenising 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() : modifying the input string while it is getting tokenised 12*/ 13 14echo "*** Testing strtok() : with modification of input string in between tokenising ***\n"; 15 16$str = "this is a sample string"; 17$token = " "; 18 19echo "\n*** Testing strtok() when string being tokenised is prefixed with another string in between the process ***\n"; 20var_dump( strtok($str, $token) ); 21// adding a string to the input string which is being tokenised 22$str = "extra string ".$str; 23for( $count = 1; $count <=6; $count++ ) { 24 echo "\n-- Token $count is --\n"; 25 var_dump( strtok($token) ); 26 echo "\n-- Input str is \"$str\" --\n"; 27} 28 29echo "\n*** Testing strtok() when string being tokenised is suffixed with another string in between the process ***\n"; 30var_dump( strtok($str, $token) ); 31// adding a string to the input string which is being tokenised 32$str = $str." extra string"; 33for( $count = 1; $count <=10; $count++ ) { 34 echo "\n-- Token $count is --\n"; 35 var_dump( strtok($token) ); 36} 37 38echo "Done\n"; 39?> 40--EXPECTF-- 41*** Testing strtok() : with modification of input string in between tokenising *** 42 43*** Testing strtok() when string being tokenised is prefixed with another string in between the process *** 44string(4) "this" 45 46-- Token 1 is -- 47string(2) "is" 48 49-- Input str is "extra string this is a sample string" -- 50 51-- Token 2 is -- 52string(1) "a" 53 54-- Input str is "extra string this is a sample string" -- 55 56-- Token 3 is -- 57string(6) "sample" 58 59-- Input str is "extra string this is a sample string" -- 60 61-- Token 4 is -- 62string(6) "string" 63 64-- Input str is "extra string this is a sample string" -- 65 66-- Token 5 is -- 67bool(false) 68 69-- Input str is "extra string this is a sample string" -- 70 71-- Token 6 is -- 72bool(false) 73 74-- Input str is "extra string this is a sample string" -- 75 76*** Testing strtok() when string being tokenised is suffixed with another string in between the process *** 77string(5) "extra" 78 79-- Token 1 is -- 80string(6) "string" 81 82-- Token 2 is -- 83string(4) "this" 84 85-- Token 3 is -- 86string(2) "is" 87 88-- Token 4 is -- 89string(1) "a" 90 91-- Token 5 is -- 92string(6) "sample" 93 94-- Token 6 is -- 95string(6) "string" 96 97-- Token 7 is -- 98bool(false) 99 100-- Token 8 is -- 101bool(false) 102 103-- Token 9 is -- 104bool(false) 105 106-- Token 10 is -- 107bool(false) 108Done 109