PHP Tutorial - PHP strtok() Function






Definition

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

Syntax

PHP strtok() Function has the following syntax.

strtok(string,split)

Parameter

Parameter Is Required Description
string Required.String to split
split Required. One or more split characters

Return

PHP strtok() Function returns a string token

Example

In the example below, the first call to strtok() uses the string argument. After that, this function only needs the split argument.


<?php
$string = "Hello world. from java2s.com.";
$token = strtok($string, " ");

while ($token != false){
   echo "$token\n";
   $token = strtok(" ");
} 
?>

The code above generates the following result.