What are potential issues with using file_get_contents() to retrieve content from a URL in PHP?

Using file_get_contents() to retrieve content from a URL in PHP may lead to security vulnerabilities if the URL is not properly validated. It can also be slow for large files or remote resources. To mitigate these issues, consider using cURL, which provides more control and security features for fetching remote content.

$url = 'https://example.com';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

if($response === false){
    echo 'Error: ' . curl_error($ch);
} else {
    // Process the response as needed
}

curl_close($ch);