Actions

 Language:
 RSS flow:


strtok statement


Overview

strtok cut a string into segments, each segment is delimited by a token. For example, a string such as "This is a good example", you can extract the words using this feature:

Syntax

string strtok ( string str , string token )

Example with strtok

<?php
 
$string = "This is\ta good\nexample";
// Also use the new lines and tabs
// as word separator
$tok = strtok($string," \n\t");
 
while ($tok !== false) {
  echo "Mot = $tok";
  $tok = strtok(" \n\t");
}
?>

Explanation

Only the first call to strtok requires two arguments. All subsequent calls require only the dice: limiter. To initialize strtok again, or again, it must again provide the str parameter. The string str is cut from that one character token is found.

The behavior of this function with an empty string has changed since PHP 4.1.0. The old behavior was to return an empty string, while the new behavior returns FALSE.

Notes

This function may return FALSE, but may also return a value equivalent to FALSE, in a usable condition if simple. Use the === operator for testing the return value of this exact function.

Go Back