tags:

views:

101

answers:

2

here is the snippit

$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

if i save this into test.php as a file. the section that im getting confused on is how the str_replace is makeing the $webRoot value come out to test.php

+1  A: 

The variable __FILE__ is the name of the current source file, or "test.php".

Ned Batchelder
That solves the mistery... sigh... Man, if you're going to post an answer, at least make it sound like one...
Seb
+2  A: 

That code will compute the absolute filesystem path ($srvRoot) and absolute URL path ($webRoot) to an application directory, I suppose, from where the current file can be addressed relatively with library/config.php.

__FILE__ is a magic constant and contains the absolute filesystem path to the file the constant is used in. $thisFile will contain that filesystem path where back-slashes are replaced by forward-slashes. $docRoot is the absolute filesystem path to the root directory that is accessible from the web.

So, for example, if __FILE__ is /var/www/htdocs/apps/foobar/library/config.php and $_SERVER['DOCUMENT_ROOT'] is /var/www/htdocs, $webRoot is /apps/foobar/ and $srvRoot is /var/www/htdocs/apps/foobar/.

Gumbo