PHP strtok()Functions

PHP String 参考手册PHP String Reference Manual

Examples

Split string by word:

In the example below, note that we only pass the string parameter to the strtok() function the first time it is called. After the first call, the function only requires the split parameter, because it knows where it is in the current string. To split a new string, call strtok() with the string parameter again:

<?php $string = "Hello world. Beautiful day today."; $token = strtok($string, " "); while ($token != false) { echo "$token<br>"; $token = strtok(" "); } ?>

Run Example »

Definition and Usage

The strtok() function splits a string into smaller strings (tokens).


Syntax

strtok(string,split)

Parameter Description
string Required. Specifies the string to be split.
split Required. Specifies one or more split characters.

Technical Details

Return value: Returns the string token.
PHP Version: 4+


PHP String 参考手册PHP String Reference Manual Other Extensions