Re: Re: validate URL
| From: | Frederic Poeydomenge | Date: | Thu, 04 Dec 2003 16:35:45 +0000 |
| Subject: | Re: Re: validate URL | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24142@lists.php.net to get a copy of this message | ||
Hi,
> Davey <davey@php.net> wrote :
> From the URI RFC, comes this amazing section:
> ...
> ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
> 12 3 4 5 6 7 8 9
> ...
> I have yet to actually get this regex to work with ereg...
the following version is working with ereg :
function ereg_parse_url($s) {
if (ereg('^(([^:/?#]+):)?([/]{2}([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?',$s,$regs)) {
return $regs;
} else {
return '';
}
}
> I think unless you need to *parse* the URI a lot of the parens could be
> removed... and moving it to PCRE instead of POSIX would be beneficial.
> This needs a regex guru for sure :D
and the following one is working with preg ;D
function preg_parse_url($s) {
if
(preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!',$s,$matches)) {
return $matches;
} else {
return '';
}
}
you can notice that the only difference with the generic URI syntax as found in
the RFC are just the ! at the start and the end of the regex... no need to be a
regex guru ;-)
Regards,
--------------------
Frederic Poeydomenge