English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP String Manual of String Functions
The strtok() function is used to mark and split strings into smaller strings (markers).
strtok(string,split)
strtok() splits the string string into several substrings, each substring is split by the character in token. This means that if there is a string such as "This is an example string", you can use the space character to split this sentence into separate words.
Note that the string parameter should only be used for the first call to the strtok function. For subsequent calls, only the token parameter will be used, as it will remember its position in the string string. If you want to start splitting a new string, you need to use the string parameter again to call strtok to complete the initialization work. Note that multiple characters can be used in the token parameter. The string will be split by any character in the parameter.
It returns a marked string.
Serial Number | Parameters and Descriptions |
---|---|
1 | string String to be split |
2 | split Specify one or more split characters |
Try the following example, splitting strings by spaces:
<?php //strtok() function, splits strings by spaces $input = "How to learn PHP well? \"; $token = strtok($input, "\t"); while ($token !== false){ echo "\$token<br>"; $token = strtok("\t"); } ?>Test and See‹/›
Output Result
How to learn PHP well?