What are some common pitfalls to avoid when using file() in PHP to read a webpage's content?

One common pitfall when using file() in PHP to read a webpage's content is not handling potential errors or exceptions properly. It's important to check for errors and handle them gracefully to prevent your script from breaking. Additionally, make sure to validate the URL before passing it to file() to avoid security risks.

$url = 'https://example.com';
$content = @file_get_contents($url);

if ($content === false) {
    echo "Error reading content from URL";
} else {
    // Process the content here
}