What are the potential reasons for encountering an unexpected server error when checking a specific URL in PHP?

Encountering an unexpected server error when checking a specific URL in PHP could be due to various reasons such as incorrect URL formatting, server misconfiguration, or network issues. To solve this issue, you can try checking the URL for any typos, ensuring that the server is properly configured to handle the request, and verifying that there are no network connectivity problems.

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

// Check if the URL is valid
if (filter_var($url, FILTER_VALIDATE_URL)) {
    // Perform the URL check here
    // For example, you can use cURL to send a request to the URL
} else {
    echo 'Invalid URL';
}