Re: Php filter validate url

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 = '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/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux