How can PHP interpret URLs when using readfile()?

When using readfile() in PHP to output the contents of a file, PHP can interpret URLs by using the file_get_contents() function to fetch the contents of the URL and then outputting it with readfile(). This allows PHP to read and output the contents of remote URLs.

$url = 'https://www.example.com/file.txt';
$content = file_get_contents($url);
header('Content-Type: text/plain');
echo $content;