How can the pathinfo() function be used to extract file extensions in PHP?
To extract file extensions in PHP, the pathinfo() function can be used. This function takes a file path as input and returns an associative array containing information about the file, including the file extension. By accessing the 'extension' key of the array, we can easily retrieve the file extension.
$file_path = '/path/to/file/example.txt';
$file_info = pathinfo($file_path);
$file_extension = $file_info['extension'];
echo $file_extension; // Outputs 'txt'
Keywords
Related Questions
- What steps should be taken to avoid potential issues when trying to add PHP to a server?
- Are there specific best practices for handling technical details retrieval from the Amazon API in PHP?
- What are the security considerations when allowing users to customize colors and sizes using PHP variables in iframes?