What are the potential issues with using the filter_var function to validate URLs in PHP?

The potential issue with using the filter_var function to validate URLs in PHP is that it may not catch all valid URLs, as it relies on the URL format specified in the RFC standard. To solve this issue, it is recommended to use a more comprehensive regular expression pattern to validate URLs.

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

if (preg_match('/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/', $url)) {
    echo "Valid URL";
} else {
    echo "Invalid URL";
}