strtok
Tag split string
strtok()
function splits the string into smaller strings (marks).
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
strtok ( string , split )
parameter | describe |
---|---|
string | Required. Specifies the string to be divided. |
split | Required. Specifies one or more split characters. |