Home >Backend Development >PHP Problem >How to use php strtok() function
In PHP, the strtok() function is used to split a string into smaller strings (marks) according to the specified delimiter, and then return the string mark; the syntax format is "strtok(string, separator)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP strtok() is used to based on the given Delimiter marks the string into smaller parts, it takes the input string as an argument along with the delimiter (as the second argument).
Syntax
strtok(string,split)
Description | |
---|---|
string | Required. Specifies the string to be split.|
split | Required. Specifies one or more delimiting characters.
Description:
This function returns a string or a range of strings separated by the given delimiter. A sequence of strings can be found by using strtok() in a while loop.Example:
<?php $string = "Hello world !"; $token = strtok($string, " "); while ($token != false) { echo "$token<br>"; $token = strtok(" "); } ?>Output:
Hello world !Recommended learning: "
PHP Video Tutorial"
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!