Something like might work for you:
$arr = array('abc.com/foo',
'localhost',
'abc+def',
'how r u',
'https://how r u',
'ftp://abc.com',
'a.b');
foreach ($arr as $u) {
$url = $u;
if (!preg_match('#^(?:https?|ftp)://#', $url, $m))
$url = 'http://' . $url;
echo "$u => ";
var_dump(filter_var($url, FILTER_VALIDATE_URL));
}
OUTPUT:
abc.com/foo => string(18) "http://abc.com/foo"
localhost => string(16) "http://localhost"
abc+def => string(14) "http://abc+def"
how r u => bool(false)
https://how r u => bool(false)
ftp://abc.com => string(13) "ftp://abc.com"
a.b => string(10) "http://a.b"
So basically wherever you notice false
as return value that is an INVALID URL for you.