Obtaining method: 1. Use the basename() function, the syntax is "basename (file path, the suffix name that needs to be removed)"; 2. Use the pathinfo() function, the syntax is "pathinfo (file path, PATHINFO_FILENAME)" .
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php is obtained without Methods for suffixed file names
1. Use the basename() function
The basename() function returns the file name part of the path. Syntax:
basename(path,suffix)
Parameter path: Indicates the path to be checked.
Parameter suffix: can be omitted, indicating the file extension. If the suffix parameter is not omitted, the file name without extension is output.
Example:
<?php $path = "/testweb/home.php"; //显示带有文件扩展名的文件名 echo basename($path); //显示不带有文件扩展名的文件名 echo basename($path,".php"); ?>
Output:
home.php home
2. Use the pathinfo() function
pathinfo () function returns information about the file path in the form of an array. Syntax:
pathinfo(path,options)
Parameter path: Indicates the path to be checked.
-
Parameter options: can be omitted, indicating the array elements to be returned, the default value is all. Can have the following values:
PATHINFO_DIRNAME: Only the directory name (dirname) is returned.
PATHINFO_BASENAME: Returns the complete file name (basename), that is, the file name with extension.
PATHINFO_EXTENSION: Returns only the extension (extension)
PATHINFO_FILENAME: Returns the file name (filename) without the extension.
Example:
<?php // 用文件名初始化变量 $file = 'demo.html'; // 仅提取文件名 $x = pathinfo($file, PATHINFO_FILENAME); // 输出 echo $x; ?>
Output:
demo
Recommended learning: "PHP Video Tutorial》
The above is the detailed content of How to get the file name without suffix in php. For more information, please follow other related articles on the PHP Chinese website!

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

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

SublimeText3 English version
Recommended: Win version, supports code prompts!

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.

Atom editor mac version download
The most popular open source editor

SublimeText3 Chinese version
Chinese version, very easy to use
