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/*from ww  w .j a  v a2  s  .  c  om*/
$string = "Hello world. from java2s.com.";
$token = strtok($string, " ");

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

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions