php中explode与split的区别介绍
首先来看下两个方法的定义:
函数原型:array split (string $pattern, string $string [, int $limit])
函数原型:array explode ( string $separator, string $string [, int $limit])
初看没有啥差别,貌似功能都一样。我就犯了这个错误。 请注意两个函数的第一个参数string $pattern和string separator,一个是$pattern说明是正则字符串,一个是$separator是普通字符串。
看下面的代码:
复制代码 代码如下:
$test = end(explode('.', 'abc.txt'));
echo $test;//output txt
换成:
复制代码 代码如下:
$test1 = end(split('.','abc.txt'));
echo $test1;//no output
用split的正确做法是:加转义符号
复制代码 代码如下:
$test1 = end(split('\.','abc.txt'));
echo $test1;//output txt
分析:"." 符号是正则表达式的关键字所以split无效,而explode有效。

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.