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
  • Binary safe comparison of several characters at the beginning of a string strncmp

    strncmp

    Binarysafecomparison
  • Return part of the string substr

    substr

    Returnpartofthestrin
  • Split the string into smaller chunks chunk_split

    chunk_split

    Splitthestringintosm
  • Translate characters or replace substrings - convert specified characters strtr

    strtr

    Translatecharacterso
  • Remove spaces (or other characters) from the beginning of the string ltrim

    ltrim

    Removespaces(orother
  • Remove HTML and PHP tags from string strip_tags

    strip_tags

    RemoveHTMLandPHPtags
  • Find the last occurrence of a specified character in a string strrchr

    strrchr

    Findthelastoccurrenc
  • Parses entered characters according to the specified format sscanf

    sscanf

    Parsesenteredcharact
Popular Articles