Home > php教程 > php手册 > body text

PHP strtok()函数的优点分析

WBOY
Release: 2016-06-06 20:32:49
Original
1761 people have browsed it

相对于explode()来说,strtok()函数可以控制节奏。按需切割字串。

其优点是:

1、可以一次定义多个分隔符。函数在执行时,是按单个分隔符来切割,而不是按整个分隔符,而explode则是按整个分隔串来切割的。正因此,explode可以用中文切割,而strtok则不行,会乱码。

2、在使用while或for配合strtok()遍历时,可以随时更换分隔符,也可以随时用break跳出终止切割。

示例1:演示用中文+explode来切割

返回:

示例2:演示更换切割符,注意后面WHILE中不再带有“H”分隔符。而只是用空格。

返回:

示例3:演示多分隔符。

返回:

返回:

示例4:演示用for来遍历:

返回:

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 Recommendations
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!