PHP strtok() 函数

PHP 教程 · 2019-01-30 12:28:24

实例

按单词分割字符串:

在下面的实例中,请注意,我们仅在第一次调用 strtok() 函数时使用了 string 参数。在首次调用后,该函数仅需要 split 参数,这是因为它清楚自己在当前字符串中所在的位置。如需分割一个新的字符串,请再次调用带 string 参数的 strtok():

<?php
$string = "Hello world. Beautiful day today.";
$token = strtok($string, " ");

while ($token != false)
{
echo "$token<br>";
$token = strtok(" ");
}
?>

定义和用法

strtok() 函数把字符串分割为更小的字符串(标记)。

语法


strtok(string,split)


参数 描述
string 必需。规定要分割的字符串。
split 必需。规定一个或多个分割字符。

技术细节

返回值: 返回字符串标记。
PHP 版本: 4+

点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html

查看所有标签

Hello World

Hello World

Hannah Fry / W. W. Norton Company / 2018-9 / GBP 17.99

A look inside the algorithms that are shaping our lives and the dilemmas they bring with them. If you were accused of a crime, who would you rather decide your sentence—a mathematically consistent ......一起来看看 《Hello World》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试