Have a look at this:

function ValidateUrl($url) {
 // Check the syntax
 if
(!preg_match("!((https?|ftp)://)(www\.)?([a-zA-Z0-9/\-]*)+\.([a-zA-Z0-9/\-]*
)+([a-zA-Z0-9/\-\.]*)?!", $url)) {
  return false;
 }
 // If it's correct, then try and open it....
 if (!@fopen($url, "r")) {
  return false;
 }
 return true;
}

if (!ValidateUrl("http://www.yoursite.com";)) {
 echo "Invalid url";
} else {
 echo "It's there.";
}

Not particularly clean, but it seems to work ok.  Will check for http,
https, ftp, followed by an optional www. followed by numbers, digits,
hyphens etc. If it gets passed that check, then the function then attempts
to open the url. You may need to play around with it a little...

~James


"John Fishworld" <[EMAIL PROTECTED]> wrote in message
004001c1d2cc$caff60e0$04010a0a@fishworld">news:004001c1d2cc$caff60e0$04010a0a@fishworld...
> Okay good point but still why doesn't it work ?
>
> thanks
> john
>
>
> > On Sun, 24 Mar 2002, John Fishworld wrote:
> > > I'm still playing about trying to validate an url
> > > www(dot)something(dot)something !
> > >
> > > I thought this would work but know
> > >
> > > if (ereg("^(w{3})(\\.)([a-zA-Z]+)(\\.)([a-z]{2,4})$", $str))
> >
> > First of all, web server hostnames don't need to start with www.
Secondly,
> > they can have any number of components (separated by periods) from 1 to
> > dozens. Thirdly, the last term doesn't have to be 4 characters or less.
> >
> > > ([a-z]{2,4})$ = at least 2 leters eg de but upto 4 eg info
> >
> > .museum...
> >
> > miguel
> >
> >
>
>



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

Reply via email to