How can the use of different file extensions or configurations affect the output when reading a website with file_get_contents in PHP?

When using file_get_contents in PHP to read a website, the file extension or configuration can affect the output if the server is not configured to recognize the specific file type. To ensure proper reading of the website, you can specify the HTTP context options to set the User-Agent header, which can help in cases where the server expects a specific user agent to serve the content.

$url = 'https://www.example.com';
$options = array(
    'http' => array(
        'method' => 'GET',
        'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
    )
);
$context = stream_context_create($options);
$content = file_get_contents($url, false, $context);
echo $content;