Re: Php filter validate url

From: Date: Sun, 26 Jun 2011 21:04:45 +0000
Subject: Re: Php filter validate url
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-313730@lists.php.net to get a copy of this message
On Sunday, 26 June 2011 at 21:59, Ashley Sheridan wrote: > On Sun, 2011-06-26 at 20:10 +0100, Stuart Dallas wrote: > > 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 = 'ð‡ > > �p³ÚsÚyýÌ•F¶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 -- S tuart Dallas 3ft9 Ltd http://3ft9.com/ > > > I've not really read the spec, so excuse me if I'm very wrong, but wouldn't > that make it more of a URI syntax validator instead of a URL syntax validator? Yes, but the referenced RFC is titled "Uniform Resource Identifiers (URI): Generic Syntax," so the only thing that's "wrong" is the FILTER_VALIDATE_URL constant. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/

« previous php.general (#313730) next »