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

How to use php strtok() function

青灯夜游
青灯夜游Original
2021-07-05 18:38:162062browse

In PHP, the strtok() function is used to split a string into smaller strings (marks) according to the specified delimiter, and then return the string mark; the syntax format is "strtok(string, separator)".

How to use php strtok() function

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP strtok() is used to based on the given Delimiter marks the string into smaller parts, it takes the input string as an argument along with the delimiter (as the second argument).

Syntax

strtok(string,split)
##ParametersDescriptionRequired. Specifies the string to be split. Required. Specifies one or more delimiting characters.
string
split

Description:

This function returns a string or a range of strings separated by the given delimiter. A sequence of strings can be found by using strtok() in a while loop.

Example:

<?php
$string = "Hello world !";
  $token = strtok($string, " ");
while ($token != false)
    {
    echo "$token<br>";
    $token = strtok(" ");
    }
?>

Output:


Hello
world
!

Recommended learning: "

PHP Video Tutorial"

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