Are there any potential pitfalls or security concerns when using file_get_contents to retrieve HTML source code?

When using file_get_contents to retrieve HTML source code, one potential pitfall is that it can be susceptible to remote code execution if the input is not properly sanitized. To mitigate this security concern, it is important to validate and sanitize the input URL before passing it to file_get_contents.

$url = filter_var($_GET['url'], FILTER_SANITIZE_URL);

if (filter_var($url, FILTER_VALIDATE_URL)) {
    $html = file_get_contents($url);
    // Process the HTML source code here
} else {
    echo "Invalid URL";
}