PHP strtok() Function
Example
Split the string one by one:
In the following example, please note that we only use the string parameter when calling the strtok() function for the first time. After the first call, the function only needs the split parameter because it knows its position in the current string. To split a new string, call the strtok() with the string parameter again:
<?php $string = "Hello world. Beautiful day today."; $token = strtok($string, " "); while ($token !== false) { echo "$token<br>"; $token = strtok(" "); } ?>
Definition and Usage
The strtok() function splits a string into smaller strings (tokens).
Syntax
strtok(string,split)
Parameters | Description |
---|---|
string | Required. Specifies the string to be split. |
split | Required. Specifies one or more delimiter characters. |
Technical Details
Return value: | Return string token (string token). |
PHP Version: | 4+ |