Re: Php filter validate url

From: Date: Sun, 26 Jun 2011 19:10:01 +0000
Subject: Re: Php filter validate url
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-313728@lists.php.net to get a copy of this message
On Sunday, 26 June 2011 at 18:31, Adam Tong wrote: > Hi, > > I wanted tu use php filters for validation to avoid regular expresions. > Is it possible that FILTER_VALIDATE_URL only checks if the string has > http:// and do not check for the format domain.something? > ---- > $url = 'http://wwwtestcom'; > $url = filter_var($url,FILTER_VALIDATE_URL); > echo $url; > ----- > > Or I am doing something wrong > > Thank you As noted in the documentation (http://php.net/filter.filters.validate), URLs are validated according to the format specified in RFC2396 (http://www.faqs.org/rfcs/rfc2396). It does not validate that it's an HTTP URL, or that the hostname contains .s. Thus, "http://wwwtestcom" is a perfectly valid URL, as is "banana://in.syrup", and anything else that can be parsed as a URL according to the rules in the above RFC. If you need to check for a specific type of URL you'll need to implement your own validation function, or google for one - there's loads out there. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/

« previous php.general (#313728) next »