Re: Php filter validate url
| From: | Ashley Sheridan | Date: | Sun, 26 Jun 2011 20:59:28 +0000 |
| Subject: | Re: Php filter validate url | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-313729@lists.php.net to get a copy of this message | ||
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
>
> --
> Stuart 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?
--
Thanks,
Ash
http://www.ashleysheridan.co.uk