php获取一个文件名的函数,PHP 文件系统函数之获取文件名及文件名后缀-php文件...

获取文件名(包含扩展):

1.用PHP 文件函数 basename获取

例:

$filename = "/home/httpd/html/index.php";

$file = basename($filename);

2.先获取位置再获取文件名

例:

$filename = "/home/httpd/html/index.php";

$pos = strrpos($filename, '/');

if ($pos === false)

{ // dot is not found in the filename

$file = $filename;

}

else

{

$basename = substr($filename, ($pos+1));

$file = $basename;

}

3.用文件路径分隔符

例:

$filename = "/home/httpd/html/index.php";

$file= end( explode( "/", $filename ) );

4.用pathinfo

例:

$filename = "/home/httpd/html/index.php";

$path_parts = pathinfo($filename);

$file = $path_parts[‘basename’]

5.用正则匹配

例:

$filename = "/home/httpd/html/index.php";

preg_match('/\/([^\/]+\..*)$/', $filename, $matches);

if($matches){

$file = $matches[1];

}

6.用数组弹出最后一个元素

$filename = "/home/httpd/html/index.php";

$file = array_pop(explode('/', $filename));

03586341746d2d31665b21bdd52bd0f3.png

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/279075.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

tasker使用手册_如何开始使用Tasker调整Android手机

tasker使用手册Tasker is a powerful app for Android that lets you customize how your phone works and automate tasks. Unfortunately, it’s got a bit of a learning curve. We’re here to show you how to get started and turn your phone into a flashlight in the …

iPhone 软件:xlate free 编码的好帮手!

功能菜单: 1 文本 2 二进制 3 Char 值 4 Base64 5 反向 如果需要把一段中文编码请选择UTF16,如果是英文就选择UTF8。对于需要经常使用编码切换的朋友是个好帮手。 也可以用来简单加密:我们先在文本状态下输入一段不想让别人知道或需要保密的文…

如何提取幻灯片表格_如何查看对Google文档,表格或幻灯片文件的最新更改

如何提取幻灯片表格The Google Suite offers you a handy way to view all the changes that have occurred in a file on Google Docs, Sheets, or Slides. This is extremely useful when you’ve made lots of changes to a file or are working as part of a team and need…

支付宝红包php,支付宝红包赏金跳转源码,一键复制红包码,裂变推广

[html]代码库支付宝到店红包搜索码跳转推广裂变-引流*{padding:0;margin:0;}.main{overflow: hidden;}a {color:black;}.main img{width:100%;outline-width:0px;vertical-align:top;}.main{position: relative;}.main .copy-container{width: 100%;height: 0.42rem;position: …

apt-get更新软件包_如何使用Apt-fast加速软件包下载和更新

apt-get更新软件包By Default, Ubuntu uses apt-get to install packages and updates. Apt-get is a good tool but you can get much faster download speeds using Apt-Fast when downloading and updating your Ubuntu box. 默认情况下,Ubuntu使用apt-get安装软…

ipad iphone开发_如何在iPad或iPhone上使用外部GPS设备

ipad iphone开发If you bought a Wi-Fi only iPad and now you wish you could use GPS with it, this is the guide for you. Follow along to hook your iPad up to an external GPS unit and/or GPS-enabled smartphone phone. 如果您购买了仅支持Wi-Fi的iPad,现…

fc-ae-1553_什么是AE-L,AF-L和*按钮,它们的作用是什么?

fc-ae-1553DSLRs and mirrorless cameras have a lot of buttons. If you’re just starting to get the hang of manually controlling your camera, you’re probably wondering what all the—seemingly non-essential—ones do. Let’s take a look at the AE-L, AF-L, AF-…

大学留级两年不敢和家人说_您说什么:如何与家人保持联系?

大学留级两年不敢和家人说Earlier this week we asked you to share your tips, tricks, and techniques for staying connected when you’re away from your home broadband connection. Now we’re back with a roundup of what you said. 本周早些时候,我们要求…

DevExpress v17.2新版亮点—WinForms篇(四)

2019独角兽企业重金招聘Python工程师标准>>> DevExpress首推团队升级培训套包,最高可省10万元!查看详情>>> 用户界面套包DevExpress v17.2终于正式发布,本站将以连载的形式为大家介绍各版本新增内容。开篇介绍了DevExpre…

Solr 11 - Solr集群模式的部署(基于Solr 4.10.4搭建SolrCloud)

目录 1 SolrCloud结构说明2 环境的安装2.1 环境说明2.2 部署并启动ZooKeeper集群2.3 部署Solr单机服务2.4 添加Solr的索引库3 部署Solr集群服务(SolrCloud)3.1 启动ZooKeeper3.2 ZooKeeper管理配置文件3.3 修改SolrCloud监听端口3.4 关联Solr与ZooKeeper3.5 分发SolrCloud服务3…

matlab怎么画一箭穿心,MATLAB学习与使用:如何绘制三维心形图 经验告诉你该这样...

MATLAB是MATrix & LABoratory(矩阵实验室)的缩写,是一款强大的科学软件,具有编程、绘图、仿真等功能。利用MATLAB绘制一款三维的心形图,然后送给心爱的姑娘,也是理工男撩妹的一项小技能。工具/材料MATLAB三维心形图操作方法01…

mac重置系统_如何在Mac上重置打印系统

mac重置系统Printers are notorious for failing frequently. A quick restart of the printer or computer usually fixes most intermittent issues, but occasionally it’s best to reset your printing settings and reinstall the printer completely. Consider this a f…

COW奶牛!Copy On Write机制了解一下

前言 只有光头才能变强 在读《Redis设计与实现》关于哈希表扩容的时候,发现这么一段话: 执行BGSAVE命令或者BGREWRITEAOF命令的过程中,Redis需要创建当前服务器进程的子进程,而大多数操作系统都采用写时复制(copy-on-w…

windows 全局变量_如何在Windows中使用全局系统环境变量

windows 全局变量Any system administrator who spends a good bit of time in the command prompt or batch scripts is probably well aware of built in environment variables Windows offers (i.e. Path, WinDir, ProgramFiles, UserProfile, etc.). If you find yourself…

twitter api使用_使用P2创建自己的Twitter风格的组博客

twitter api使用Would you like a great way to post stuff quickly online and communicate with your readers? Here’s how you can use the P2 theme to transform WordPress into a great collaboration and communications platform. 您是否想以一种很好的方式在网上快…

10_30_unittest

1、断言 1)、self.assertEqual(2,res)#期望值qian、结果值hou2)TextTestRunner 源码 必要的参数3)测试结果 上下文管理器 with open("test.txt",w,encodingutf-8) as file:runner unittest.TextTestRunner(streamfile,verbosity2)…

laravel graphql php,结合 Laravel 初步学习 GraphQL

本文字数:7134,大概需要14.27分钟。按照官网所述的:A query language for your API一种用于 API 的查询语言GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a…

wi-fi共享大师免广告_如何保护Wi-Fi网络免受入侵

wi-fi共享大师免广告Insecure Wi-Fi is the easiest way for people to access your home network, leech your internet, and cause you serious headaches with more malicious behavior. Read on as we show you how to secure your home Wi-Fi network. 不安全的Wi-Fi是人们…

【材质】色彩基础

RBG颜色空间 目前,绝大部分显示器采用的是RGB颜色标准,因此几乎所有软件也采用此标准,UE4也不例外。 R、G、B这三个字母分别代表红色(red)、绿色(green)、蓝色(blue)三条…

使用mintty(_如何使用Mintty改善Cygwin控制台

使用mintty(Cygwin’s great for getting some Linux command-line goodness in Windows, but using the Windows Shell to access it kills some of that magic. Using Mintty and a few other methods, you can make the experience much more luxurious. Cygwin非常适合在Wi…