How can the pathinfo() function be used to extract file extensions from dynamic URLs in PHP?

To extract file extensions from dynamic URLs in PHP, you can use the pathinfo() function. This function parses a path and returns an associative array containing information about the path. To extract the file extension, you can access the 'extension' key in the array returned by pathinfo(). This allows you to easily retrieve and work with file extensions in dynamic URLs.

$url = "https://www.example.com/images/photo.jpg";
$extension = pathinfo($url, PATHINFO_EXTENSION);
echo $extension; // Output: jpg