How can SSL be implemented to ensure secure data transmission when using file_get_contents()?

When using file_get_contents() to retrieve data from an HTTPS URL, it's important to ensure that the data transmission is secure by implementing SSL verification. This can be achieved by setting the 'verify_peer' and 'verify_peer_name' options to true in a stream context before making the request. This will enable SSL verification and ensure that the data is transmitted securely.

$url = 'https://example.com/data';
$options = array(
    'ssl' => array(
        'verify_peer' => true,
        'verify_peer_name' => true
    )
);
$context = stream_context_create($options);
$data = file_get_contents($url, false, $context);

// Use the retrieved data securely