How to get a File Extension in PHP ?
In this article, we will learn how to get the current file extensions in PHP.
Input : c:/xampp/htdocs/project/home Output : "" Input : c:/xampp/htdocs/project/index.php Output : ".php" Input : c:/xampp/htdocs/project/style.min.css Output : ".css"
$_SERVER is an array of stored information such as headers, paths, and script locations. These entries are created by the webserver. There is no other way that every web server will provide any of this information.
- ‘SCRIPT_NAME’ gives the path from the root to include the name of the directory.
Method 2: The following method uses a predefined function pathinfo(). In the output, the “Name:” shows the name of the file and “Extension:” shows the file extension.
Name: 001510d47316b41e63f337e33f4aaea4 Extension: php
Name: file.index Extension: php