Current Location: Home> Function Categories> strtok

strtok

Tag split string
Name:strtok
Category:String
Programming Language:php
One-line Description:Split the string into smaller strings.

Definition and usage

strtok() function splits the string into smaller strings (marks).

Example

Split strings one by one:

In the following example, please note that we only use the string parameter when we call strtok() function for the first time. After the first call, the function only needs the split parameter, because it knows where it is in the current string. To split a new string, call strtok() with string parameter again:

 <?php
$string = "Hello world. Beautiful day today." ;
$token = strtok ( $string , " " ) ;

While ( $token !== false )
{
echo " $token <br>" ;
$token = strtok ( " " ) ;
}
?>

Try it yourself

grammar

 strtok ( string , split )
parameter describe
string Required. Specifies the string to be divided.
split Required. Specifies one or more split characters.
Similar Functions
Popular Articles