PHP获取文件扩展名五种以上的方法和注释
在PHP面试中或者考试中会有很大几率碰到写出五种获取文件扩展名的方法,下面是我自己总结的一些方法
$file = ‘需要进行获取扩展名的文件.php’;
//第一种,根据.拆分,获取最后一个元素的值
function getExt1{
return end(explode(".",$file);)
}
//第二种,获取最后一个点的位置,截取
function getExt2{
return substr($file,strrpos($file,'.')+1);
}
//第三种,根据.拆分,获取最后一个元素的值
function getExt3($file) {
return array_pop(explode(‘.’,$file));
}
//第四种,pathinfo
function getExt5($file) {
$arr = pathinfo($file);
return $arr['extension'];
//或者这样return pathinfo($file,PATHINFO_EXTENSION);
}
//第五种,正则,子模式
function getExt6$file){
preg_match("/(gif | jpg | png)$/",$file,$match);
$match=$match[0];
}
//第六种,正则反向引用
function getExt7($file){
$match=preg_replace("/.*\.(\w+)/" , "\\1" ,$file );
echo $match;
}
PHP获取文件扩展名五种以上的方法和注释的更多相关文章
- PHP中获取文件扩展名的N种方法
PHP中获取文件扩展名的N种方法 从网上收罗的,基本上就以下这几种方式: 第1种方法:function get_extension($file){substr(strrchr($file, '.'), ...
- PHP获取文件扩展名的多种方法
PHP获取文件扩展名的N种方法. 第1种方法: function get_extension($file) { substr(strrchr($file, '.'), 1): } 第2种方法: fun ...
- python获取文件扩展名的方法(转)
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧.具体实现方法如下: 1 2 3 4 import os.path def file_extension(path ...
- python获取文件扩展名的方法
主要介绍了python获取文件扩展名的方法,涉及Python针对文件路径的相关操作技巧 import os.path def file_extension(path): ] print file_ex ...
- PHP中获取文件扩展名
function get_extension($file) { return substr(strrchr($file, '.'), 1) ; } function get_extension($fi ...
- PHP获取文件扩展名的五种方式
这是我应聘实习时遇到的一道笔试题: 使用五种以上方式获取一个文件的扩展名. 要求:dir/upload.image.jpg,找出 .jpg 或者 jpg , 必须使用PHP自带的处理函数进行处理,方法 ...
- PHP 获取文件扩展名的五种方式
第一种 substr(strrchr("http://www.xxx.com/public/abc.jpg", '.'), 1); string strrchr('string', ...
- PHP 获取文件 扩展名 的常用方法小结【五种方式】
1: function getExt1($filename) { $arr = explode('.',$filename); return array_pop($arr);; } ...
- PHP获取文件扩展名的常用方法小结【五种方式】
方法1: function getExt1($filename) { $arr = explode('.',$filename); return array_pop($arr);; } ...
随机推荐
- centos7常见问题(更新。。。)
1.网络设置 装好CentOS7后,我们一开始是上不了网的 DHCP 这时候,可以输入命令dhclient,可以自动获取一个IP地址,再用命令ip addr查看IP 不过这时候获取的IP是动态的,下次 ...
- JDBC概述及JDBC完成对Oracle的增删改查
什么是JDBC JDBC(Java Data Base Connectivity,Java数据库连接),是一种用于执行SQL语句的Java API,为多种关系数据库提供统一访问.它由一组用Java语言 ...
- 8.CNN应用于手写字识别
import numpy as np from keras.datasets import mnist from keras.utils import np_utils from keras.mode ...
- PAT乙级1024
题目链接 https://pintia.cn/problem-sets/994805260223102976/problems/994805297229447168 题解 第一遍也是没有全部AC,有3 ...
- Mac下 CMD常用命令
1.常用命令 pwd 当前工作目录 cd(不加参数) 进root cd(folder) 进入文件夹 cd .. 上级目录 cd ~ 返回root cd - 返 ...
- five rendering ideas 里获取csm的 shadow边界做 pcf
http://advances.realtimerendering.com/s2011/White,%20BarreBrisebois-%20Rendering%20in%20BF3%20(Siggr ...
- 09-sp_lock和sys.dm_tran_locks的用法
一.总结 1.网址 https://docs.microsoft.com/zh-cn/sql/relational-databases/system-stored-procedures/sp-lock ...
- idea的maven项目运行出错_java.io.FileNotFoundException: class path resource [spring/sprint-tx.xml] cannot be opened because it does not exist
前提:idea maven ssm 错误信息如下: 严重: Exception sending context initialized event to listener instance of ...
- gRPC应用实践
What is RPC? Remote Procedure Call is a high-level model for client-server communication. Assume the ...
- vue 运行脚手架报错
报错: You are using the runtime-only build of Vue where the template compiler is not available. Either ...