To find the extension of a file in PHP, you can use a combination of the pathinfo()
function and string manipulation.
Here is an example code block that demonstrates how to find the extension of a file:
main.php113 chars4 lines
In this example:
$filename
variable holds the name of the file for which we want to find the extension.pathinfo()
function returns an associative array with information about the file path, including the extension. We use the PATHINFO_EXTENSION
constant to specify that we want to retrieve only the extension from the array.$extension
variable holds the extension of the file.echo
statement to print the extension to the screen. In this case, it will output "jpg".gistlibby LogSnag