How can PHP be used to dynamically generate file extensions?

To dynamically generate file extensions in PHP, you can use the pathinfo() function to extract the file extension from a given file path. This function returns an associative array containing information about the file path, including the file extension.

$file_path = 'example/file.txt';
$file_extension = pathinfo($file_path, PATHINFO_EXTENSION);
echo $file_extension; // Output: txt