What are the potential issues with the URL validation and checking in the PHP script?

One potential issue with URL validation and checking in a PHP script is that it may not properly handle all valid URL formats, leading to false negatives. To solve this, you can use the filter_var function with the FILTER_VALIDATE_URL filter to perform more robust URL validation.

$url = "https://www.example.com";

if (filter_var($url, FILTER_VALIDATE_URL)) {
    echo "URL is valid";
} else {
    echo "URL is not valid";
}