Re: Re: How can I tell if a path is absolute?
| From: | Trejkaz Xaoza | Date: | Sun, 18 Jul 2004 01:22:20 +0000 |
| Subject: | Re: Re: How can I tell if a path is absolute? | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-190867@lists.php.net to get a copy of this message | ||
Curt Zirzow wrote:
> A simple workaround is testing OS:
>
> if (windows)
> // use realpath method
> } else {
> $absolute = $path{0} == '/';
> }
I don't know what the "realpath" method is since every one I've been given
that involves realpath so far doesn't work.
But here's what I'm doing now:
function is_absolute($path)
{
$regex = (PHP_OS == 'WINNT' || PHP_OS == 'WIN32')
? "/^([a-z][A-Z]:)?[\/\\]/"
: "/^\//";
return (boolean) preg_match($regex, $path);
}
Does that look safe enough? It works for Linux but since I have no Windows
environments to test on I have no idea if it works properly on Windows.
TX
--
'Every sufficiently advanced technology is indistinguishable from magic' -
Arthur C Clarke
'Every sufficiently advanced magic is indistinguishable from technology' -
Tom Graves
Email: Trejkaz Xaoza <trejkaz@xaoza.net>
Web site: http://xaoza.net/trejkaz/
Jabber ID: trejkaz@jabber.xaoza.net
GPG Fingerprint: 9EEB 97D7 8F7B 7977 F39F A62C B8C7 BC8B 037E EA73