What are some alternative methods to extract the file name and file extension separately in PHP, and what are the advantages of using these methods?
One alternative method to extract the file name and file extension separately in PHP is by using the `pathinfo()` function. This function returns an associative array containing information about a file path, including the file name and extension. By using this function, you can easily extract the file name and extension without having to manipulate the file path string manually.
$file_path = 'example.txt';
$file_info = pathinfo($file_path);
$file_name = $file_info['filename'];
$file_extension = $file_info['extension'];
echo 'File Name: ' . $file_name . '<br>';
echo 'File Extension: ' . $file_extension;