


This article mainly introduces in detail how PHP can obtain the file suffix name.
PHP Obtaining the file suffix name is a common operation for PHP learners, whether during the interview process or during self-study of PHP novices. Getting the file suffix name with PHP is a very common knowledge point that needs to be mastered.
Now we will give you a summary of PHP to obtain the file extension , which is the two methods of suffix name!
1. Through pathinfo
First of all, everyone should know that the pathinfo() function can return an associative array containing path information, then in the following code, we use pathinfo to obtain 1 The path information of the .txt file.
<?php var_dump(pathinfo('1.txt'));
The return information is as shown below:
#What we need to pay attention to in the picture is the extension element. The value of extension here is txt, which means File suffix name.
Then if we want to get the individual file suffix here, we can do the following:
1, PATHINFO_EXTENSION
<?php echo pathinfo('1.txt',PATHINFO_EXTENSION);
directly Use the PATHINFO_EXTENSION constant in pathinfo to obtain the suffix name
2 and array element
<?php $data = (pathinfo('1.txt')); echo $data['extension'];
. Just output the value of the array element directly here. The result of obtaining the file extension is the same as above.
2. Through substr
substr(), you can extract the specified number of characters starting from the start subscript in the string, which is to intercept one part of the string. Everyone should know about functions.
echo substr('1.txt',2);
Here we directly use substr to intercept and obtain the file suffix name. However, this method is best used only for simple file names. This substr method is not recommended for complex file names.
Generally involves the operation of obtaining the file name suffix. It is recommended to use the first method: pathinfo.
This article is about the specific method of obtaining the file suffix name in PHP. If you want to learn more about PHP, you can check out the PHP video tutorial on the PHP Chinese website.
The above is the detailed content of What are the ways to get the file extension in PHP? (Pictures + Videos). 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

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

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