The strtok() function splits a string into smaller strings (tokens).
PHP strtok() Function has the following syntax.
strtok(string,split)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to split |
split | Required. | One or more split characters |
PHP strtok() Function returns a string token
In the example below, the first call to strtok() uses the string argument. After that, this function only needs the split argument.
<?php
$string = "Hello world. from java2s.com.";
$token = strtok($string, " ");
while ($token != false){
echo "$token\n";
$token = strtok(" ");
}
?>
The code above generates the following result.