首先來看下兩個方法的定義:
函數原型: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
echo $test1;//output txt