Re: finding the web root
| From: | Nathan Nobbe | Date: | Tue, 08 Jun 2010 21:00:26 +0000 |
| Subject: | Re: finding the web root | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-305983@lists.php.net to get a copy of this message | ||
On Tue, Jun 8, 2010 at 12:27 PM, Tanel Tammik <keevitaja@gmail.com> wrote:
> Hi,
>
> i like to find the web root where the current file is. is there a better
> solution? it must work both on linux and windows machines...
>
> <?php
> $root = explode('/', $_SERVER['DOCUMENT_ROOT']);
> $cwd = explode(DIRECTORY_SEPARATOR, __DIR__);
> $web_root = '/' . implode('/', array_diff($cwd, $root));
> echo $web_root;
> ?>
$_SERVER['DOCUMENT_ROOT']
although a post on the manual mentions some variability between
environments.
-nathan