HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

strtok

Description

The strtok of String for PHP tokenize string.

Syntax

strtok(
    string $string,
    string $token
): string|false
strtok(
    string $token
): string|false

Parameters

string

The string being split up into smaller strings (tokens).

token

The delimiter used when splitting up string.

Return

A string token, or false if no more tokens are available.

Examples

1 · string token · \n

<?

$string = "string1\nstring2";
$token = "\n";

$return = strtok($string, $token);

echo $return;
string1

2 · string token · \n\t

<?

$string = "string1\nstring2\tstring3 string4";
$token = "\n\t ";

$return = strtok($string, $token);

echo $return;
string1

3 · token

<?

$token = "\n\t ";

$return = strtok($token);

var_dump($return);
bool(false)

4 · token · while

<?

$string = "string1\nstring2\tstring3 string4";
$token = "\n\t ";

$return = strtok($string, $token);

while($return !== false)
{
    echo "$return<br>";

    $return = strtok($token);
}
string1<br>string2<br>string3<br>string4<br>