php split() 函数的用法
PHP函数split()的基本语法为:array split ( string $pattern, string $string [, int $limit] )。我们向大家举了两个例子来具体讲解这个函数的使用方法。 对于初学者来说,掌握PHP中常用函数的用法,是其继续学习的基
- PHP函数split()的基本语法为:array split ( string $pattern, string $string [, int $limit] )。我们向大家举了两个例子来具体讲解这个函数的使用方法。
对于初学者来说,掌握PHP中常用函数的用法,是其继续学习的基础。今天我们就为大家详细介绍有关PHP函数split()的一些使用方法,希望大家能通过这篇文章介绍的内容增加自己的知识库。
说明
array split ( string $pattern, string $string [, int $limit] )
提示
preg_split() 函数使用了 Perl 兼容正则表达式语法,通常是比PHP函数split()更快的替代方案。如果不需要正则表达式的威力,则使用 explode() 更快,这样就不会招致正则表达式引擎的浪费。
本函数返回一个字符串数组,每个单元为 string 经区分大小写的正则表达式 pattern 作为边界分割出的子串。如果设定了 limit,则返回的数组最多包含 limit 个单元,而其中最后一个单元包含了 string 中剩余的所有部分。如果出错,则 split() 返回 FALSE。
将 /etc/passwd 中的前四个字段分割出来:
例 1839. PHP函数split()例子
php list($user, $pass, $uid, $gid, $extra) = split (":", $passwd_line, 5); ?>
如果字符串中有 n 个与 pattern 匹配的项目,则返回的数组将包含 n+1 个单元。例如,如果没有找到 pattern,则会返回一个只有一个单元的数组。当然,如果 string 为空也是这样。
解析可能用斜线,点,或横线分割的日期:
例 1840. PHP函数split()例子
php
// 分隔符可以是斜线,点,或横线
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year
\n";
?>
想仿效 Perl 中类似的 @chars = split('', $str) 行为,请参考 preg_split() 或 str_split() 函数中的例子。
注意 pattern 是一个正则表达式。如果想要用的分割字符是正则表达式中的特殊字符,要先将其转义。如果觉得PHP函数split()(或其它任何 regex 函数)行为古怪的话,请阅读包含在 PHP 发行包中 regex/ 子目录下的 regex.7 文件。该文件是手册页面格式,可以用类似 man /usr/local/src/regex/regex.7 的命令来阅读

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
