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