First, let’s look at the definitions of the two methods:
Function prototype: array split (string $pattern, string $string [, int $limit])
Function prototype: array explode ( string $ separator, string $string [, int $limit])
At first glance, there is no difference, and they seem to have the same functions. 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 regular string, and the other is that $separator is an ordinary string.
Look at the code below:
Copy the code The code is as follows:
$test = end(explode( '.', 'abc.txt'));
echo $test;//output txt
Replace with:
Copy code The code is as follows:
$test1 = end(split('.','abc.txt'));
echo $test1;//no output
The correct way to use split is to add escape symbols
Copy the code The code is as follows:
$ test1 = end(split('.','abc.txt'));
echo $test1;//output txt
Analysis: "." symbol is a regular expression The formula keyword is so split is invalid, but explode is valid.
http://www.bkjia.com/PHPjc/326095.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326095.htmlTechArticleFirst let’s look at the definitions of the two methods: Function prototype: array split (string $pattern, string $string [ , int $limit]) Function prototype: array explode ( string $separator, string $string...