How to validate URL in php? [duplicate]

0

How do I validate a URL in php? Example: I need the user to enter a url, ex: google.com.

But I need the url to be in the format: www.google.com and if it enters any format other than that it returns an error for it to correct.

If he types specific pages as well. Example www.google.com/images. I need it to validate only up to .br or .com etc ... only up to the domain. How do I?

    
asked by anonymous 14.05.2018 / 21:00

1 answer

0

I solved my problem, using link .

Example:

$url = parse_url('http://facebook.com.br/imagens');
unset($url['host']); 
unset($url['scheme']);
if (count($url)) //url inválida
    
15.05.2018 / 15:43