分享一下一些关于PHP多种方式获取文件的后缀名的方法(有的是从网上看的)。
1. function substr_1($fileName) {
return strrchr($fileName,'.');
}
2. function substr_2($fileName) {
$position = strrpos($fileName,'.');//返回最后一次出现的位置
return substr($fileName,$position );
}
3. function substr_3($fileName) {
return end(explode('.',$fileName));
}
4. function substr_4($fileName) {
$arr = explode('.',$fileName);
return $arr[count($arr)-1];
}
5. function substr_5($fileName) {
$p = pathinfo($fileName);
return $p['extension'];
}
6. function substr_6($fileName) {
return pathinfo($fileName,PATHINFO_EXTENSION);
}
7. function substr_7($fileName) {
return array_pop(explode('.',$fileName));
}