I can't for the life of me figure out how to use filter_var to validate whether a URL is valid  when it optionally contains the scheme. 
So for example, I would like both 
https://www.google.com and www.google.com to pass validation from filter_var.
I've tried using the FILTER_FLAG_HOST_REQUIRED flag exclusively:
filter_var("www.google.com", FILTER_VALIDATE_URL, ['flags' => FILTER_FLAG_HOST_REQUIRED])
and also by negating FILTER_FLAG_SCHEME_REQUIRED with FILTER_FLAG_HOST_REQUIRED:
filter_var("www.google.com", FILTER_VALIDATE_URL, ~FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED)
and with just negating FILTER_FLAG_SCHEME_REQUIRED: filter_var("www.google.com", FILTER_VALIDATE_URL, ~FILTER_FLAG_SCHEME_REQUIRED)
 
    