How to use php strtok() function

青灯夜游
Release: 2023-03-11 09:12:01
Original
2017 people have browsed it

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)
Copy after login
##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(" ");
    }
?>
Copy after login

Output:


Hello
world
!
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!