当前位置:网站首页>PHP seven methods to obtain complete instances of file name suffixes [collect]
PHP seven methods to obtain complete instances of file name suffixes [collect]
2022-06-22 09:02:00 【YUJIANYUE】
The following schemes are collected from the network and sorted out by myself , Non reprint, non translation, non originality
<?php
$filename = "chalide.com.exe.xlsx";
// Method 1:
function getExt1($filename){
$type = substr($filename, strrpos($filename, ".")+1);
return $type;
}
echo "<p>getExt1 " . getExt1($filename) . "</p>";
// Method 2:
function getExt2($filename){
$type = pathinfo($filename);
return strtolower($type["extension"]);
}
echo "<p>getExt2 " . getExt2($filename) . "</p>";
// Method 3:
function getExt3($filename){
$type =explode("." , $filename);
$count=count($type)-1;
return $type[$count];
}
echo "<p>getExt3 " . getExt3($filename) . "</p>";
// Method 4:
function getExt4($filename){
$arr = explode('.',$filename);
return array_pop($arr);;
}
echo "<p>getExt4 " . getExt4($filename) . "</p>";
// Method 5:
function getExt5($filename){
return strrchr($filename,'.');
}
echo "<p>getExt5 " . getExt5($filename) . "</p>";
// Method 6:
function getExt6($filename){
$str = strrev($filename);
return strrev(strchr($str,'.',true));
}
echo "<p>getExt6 " . getExt6($filename) . "</p>";
// Method 7:
function getExt7($filename){
$str = preg_match_all('/\.[a-zA-Z0-9]+$/', $filename, $match);
return $match[0][0];
}
echo "<p>getExt7 " . getExt7($filename) . "</p>";
// programme 7 You can also use many other regular expressions 、 And explode+ Abandoned end()
?>边栏推荐
- [target detection] | detection error mechanism why object detectors fail: investigating the influence of the dataset
- IP address (IPv4)
- 15 命令模式
- 14 responsibility chain mode
- 07 适配器模式
- Crawling microblog comments | emotional analysis of comment information | word cloud of comment information
- 20 状态模式
- Chapter II exercise | MNIST dataset | Titanic dataset | image enhancement
- Thread. Source code analysis of start() method
- 项目优化+上线(掌握了么?)
猜你喜欢

14 responsibility chain mode

pytorch OSError: DLL load failed: 问题解决方法

15 命令模式

【Tensorboard】所有雷区都踩,一文解决你所有问题

Solid from entry to practice (end)

电机学感应电动机重点知识总结(现有题目中反映的)

医疗信息管理系统数据库--MySQL

Thread. Source code analysis of start() method

滴滴二面总结
![[path planning] auxiliary points and multi segment Bessel smoothing RRT](/img/0c/74055c93a11b9be18dfec1058796c2.jpg)
[path planning] auxiliary points and multi segment Bessel smoothing RRT
随机推荐
Solidity from introduction to practice (IV)
Webrtc series - iceconfig and stunping failure handling for network transmission
07 adapter mode
【node】快收下爬虫,我们不再为数据发愁
Solid from entry to practice (end)
【路径规划】辅助点与多段贝塞尔平滑RRT
11 外观模式
开发报错记录
无线路由攻击和WiFi密码破解实战[渗透技术]
Manually mining XSS vulnerabilities
File upload attack and protection
10 decoration mode
Read all files under the folder in the jar package
【node】理论+实践让你拿下session、cookie
Why can MySQL indexes improve query efficiency so much?
XSS vulnerability attack
Solidity from introduction to practice (V)
Remove the restriction of video memory occupied by tensorflow GPU
pytorch OSError: DLL load failed: 问题解决方法
项目优化+上线(掌握了么?)