What role does the Content Type header play in resolving formatting issues when retrieving data with file_get_contents() in PHP?

When retrieving data with file_get_contents() in PHP, the Content Type header plays a crucial role in resolving formatting issues. By specifying the Content Type header, you can inform the server about the type of data being sent, allowing it to properly format the response. This is particularly important when dealing with APIs or remote servers that return data in different formats.

$url = 'https://api.example.com/data';
$options = [
    'http' => [
        'header' => "Content-Type: application/json\r\n"
    ]
];
$context = stream_context_create($options);
$data = file_get_contents($url, false, $context);

// Process the retrieved data