Home >Backend Development >PHP Problem >How to use php strtok function?
php The strtok function is used to split a string into smaller strings (marks). Its syntax is strtok (string, split). The parameter string is required and specifies the string to be split; split is required and specifies one or more separator characters.
#php How to use strtok function?
Definition and usage
strtok() function splits a string into smaller strings (tokens).
Syntax
strtok(string,split)
Parameters
string Required. Specifies the string to be split.
split Required. Specifies one or more delimiting characters.
Return value: Returns the string token.
PHP Version: 4
Example
Split the string one by one:
In the following example, please note that we only The first time the strtok() function is called, the string parameter is used. After the first call, the function only requires the split parameter because it knows where it is in the current string. To split a new string, call strtok() with the string parameter again:
<?php $string = "Hello world. Beautiful day today."; $token = strtok($string, " "); while ($token !== false) { echo "$token<br>"; $token = strtok(" "); } ?>
Output:
Hello world. Beautiful day today.
The above is the detailed content of How to use php strtok function?. For more information, please follow other related articles on the PHP Chinese website!