How can you query a file extension in PHP?
To query a file extension in PHP, you can use the pathinfo() function to get information about a file path, including the file extension. This function returns an associative array with elements like 'dirname', 'basename', 'extension', and 'filename'. By accessing the 'extension' element of the array, you can retrieve the file extension.
$file_path = 'example.txt';
$file_extension = pathinfo($file_path, PATHINFO_EXTENSION);
echo "The file extension is: $file_extension";
Keywords
Related Questions
- What are the best practices for automatically generating and storing image links in a database using PHP?
- What are the best practices for outputting time calculations in PHP scripts to ensure accurate results across different environments?
- What is the difference between using MySQL functions and ODBC functions in PHP for database operations?