Home / PHP Tips Generated By ChatGPT / Validating a URL with filter_var() in PHP Check if a given string is a valid URL. Source Code $url = "https://www.example.com"; if (filter_var($url, FILTER_VALIDATE_URL)) { echo "This is a valid URL."; } else { echo "Invalid URL."; }