


This article mainly introduces the method of obtaining the file name and extension in PHP. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look.
php gets the file name and extension
1.basename()-returns the file name of the path
Please see the following php code:
<?php $path = "/usr/www/html/index.php"; echo basename($path)."<br>"; //如果选择suffix则忽略扩展名 echo basename($path,".php"); ?>
Run result:
index.php
index
2.dirname()-Returns the file path of the current script!
php code:
<?php //——FILE返回文件完整路径 $dir = dirname(FILE); echo $dir; ?>
Running result:
F:\web\zend\exercise
3.pathinfo() returns an associated arraycontaining path information.
Includes the following array units: path name dirname, file name basename and extension name extension.
Please see the simple code demonstration below:
<?php $path = "/usr/www/html/index.php"; $pathinfo = pathinfo($path); echo "目录名称:$pathinfo[dirname]<br>"; echo "文件名称:$pathinfo[basename]<br>"; echo "扩展名:$pathinfo[extension]"; ?>
Run result:
Directory name:/usr/www/html
File name: index.php
Extension: php
##4.realpath -- Returns the normalized absolute path name
The php code is as follows:<?php $path = "./exercise/php.txt"; $realpath = realpath($path); echo $realpath; ?>
Finally, pay attention to a little tip: File paths with different pathsOperatorsPossibly, different, you can use "/" and "\" under Windows,
Only "/" can be used under Linux, so when developing, it is recommended to use "/", as I wrote the file path above!The above is the detailed content of Detailed explanation of how to get file name and extension in php. For more information, please follow other related articles on the PHP Chinese website!

WebP或WebPicture是由Google开发的一种现代图像格式,最近已被业界广泛使用。这些图像比JPG,JPEG或PNG文件小,从而提高了页面加载速度,并从SEO的角度来看使它们很有价值。但是如何在Windows11中打开WebP文件?鉴于它是一种相对较新的图像格式,于2010年<>月首次宣布,兼容性必然是一个问题。一些照片编辑软件仍然不支持文件扩展名。但事情变化很快!Windows11是否支持WebP?虽然WebP图像文件与之前的Windows11不兼容,但M

您在传输文件时是否遇到过任何问题,并且禁止您这样做?好吧,许多Windows用户最近报告说,他们在将文件复制并粘贴到文件夹中时遇到了问题,其中抛出了一个错误,提示“目标文件夹的文件名太长”。此外,其他一些Windows用户在打开任何文件时表示失望,并说“文件名或扩展名太长”,他们无法打开文件。这不允许他们将文件传输到任何其他文件夹,这让用户感到失望。在分析问题时,我们提出了一系列解决方案,可能有助于缓解问题,用户可以轻松传输文件。如果您也遇到类似情况,请参阅此帖子以了解更多信息。来源:https

除非你知道它的扩展名,否则拥有一个文件并不意味着什么。有些文件没有扩展名。大多数情况下,扩展可能只是被隐藏了,您可以使用第1节中列出的方法从Windows文件资源管理器本身轻松找到它。即使该文件实际上没有扩展名,也可以按照第2节中列出的方法轻松找到。最后,当您知道文件的扩展名后,您可以按照第3节中的步骤找到合适的应用程序来打开您的文件。因此,本文是您所有文件扩展名问题的完整解决方案。希望你喜欢阅读!第1节:如何确定文件是否有扩展名打开没有扩展名的文件的第一步是确保该文件确实没有扩展名。这

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

文件格式和扩展名不匹配怎么解决在计算机使用过程中,经常会遇到文件格式和扩展名不匹配的情况。当我们尝试打开一个文件时,系统可能会提示“无法打开文件”或“文件格式不受支持”。这种情况可能会让人感到困惑和失望,但其实解决这个问题并不难,只需要一些简单的步骤就可以解决。首先,我们需要了解文件格式和扩展名的含义。文件格式指的是文件的存储方式和编码方式,例如文本文件是以

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
