I encountered some problems when using split today. I still don’t have a deep understanding of the function, so I’ll close it up and mark it
First let’s look at the definitions of the two methods:
Function prototype: array split (string $pattern, string $string [, int $limit])
Function prototype: arrayexplode(string $separator, string $string [, int $limit])
At first glance, there is no difference, it seems to have the same function it's the same. I made this mistake. Please note that the first parameters of the two functions are string $pattern and string separator. One is that $pattern is a regularstring, and the other is that $separator is an ordinary string.
Look at the code below:
The code is as follows:
$test = end(explode('.', 'abc.txt')); echo $test;//output txt
Replace with:
The code is as follows:
$test1 = end(split('.','abc.txt')); echo $test1;//no output
The correct way to use split is: addescape character
The code is as follows:
$test1 = end(split('\.','abc.txt')); echo $test1;//output txt
Analysis: "." symbol isregular The expressionis a keyword so split is invalid, but explode is valid.
The above is the detailed content of The difference between explode() function and split() function in php. For more information, please follow other related articles on the PHP Chinese website!