Home >Backend Development >PHP Problem >How to use php strtok function?

How to use php strtok function?

藏色散人
藏色散人Original
2019-05-30 13:08:232863browse

php The strtok function is used to split a string into smaller strings (marks). Its syntax is strtok (string, split). The parameter string is required and specifies the string to be split; split is required and specifies one or more separator characters.

How to use php strtok function?

#php How to use strtok function?

Definition and usage

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

Syntax

strtok(string,split)

Parameters

string Required. Specifies the string to be split.

split Required. Specifies one or more delimiting characters.

Return value: Returns the string token.

PHP Version: 4

Example

Split the string one by one:

In the following example, please note that we only The first time the strtok() function is called, the string parameter is used. 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(" ");
}
?>

Output:

Hello
world.
Beautiful
day
today.

The above is the detailed content of How to use php strtok function?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn