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
  • Calculate the sha1 hash value of a string sha1

    sha1

    Calculatethesha1hash
  • Calculate the last occurrence of the specified string in the target string (case insensitive) strripos

    strripos

    Calculatethelastoccu
  • Write the formatted string to the stream fprintf

    fprintf

    Writetheformattedstr
  • The case-insensitive version of str_replace str_ireplace

    str_ireplace

    Thecase-insensitivev
  • Binary safe string comparison strcmp

    strcmp

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

    strrchr

    Findthelastoccurrenc
  • Convert string to lowercase strtolower

    strtolower

    Convertstringtolower
  • Find the location where the string first appears (case insensitive) stripos

    stripos

    Findthelocationwhere
Popular Articles