Page 1 of 1

$_SERVER["SCRIPT_NAME"]

Posted: Fri Feb 20, 2004 10:41 am
by JayBird
how can i do the following

$_SERVER["SCRIPT_NAME"] contains something like /pl_generator/generated/test.php

Where test.php can be anything of any length.

How can i just return /pl_generator/generated/ - basically, just the root relative path.

Mark

Posted: Fri Feb 20, 2004 11:31 am
by Ixplodestuff8
If you know the filename, try this

Code: Select all

<?php
str_replace ( $filename, '', $_SERVER['SCRIPT_NAME'] );
?>
if not, try somthing like this

Code: Select all

<?php
$script_name = $_SERVER['SCRIPT_NAME'];
$path = explode ( '/', $script_name );
$counter = count ( $path );
$path[$counter - 1] = NULL;
$output = implode ( '/', $path );

?>

Posted: Fri Feb 20, 2004 1:32 pm
by McGruff
See [php_man]pathinfo[/php_man].

Watch out for the dot bug (excerpt from user comments):
If you use the function on a dir and the last dir in the path has a . in its name, then the function thinks that it's a file

Posted: Fri Feb 20, 2004 1:34 pm
by markl999
$path = dirname($_SERVER['SCRIPT_NAME']);

??

Posted: Fri Feb 20, 2004 1:54 pm
by redhair
or: dirname(dirname(__FILE__))

just see: http://www.php.net/manual/en/function.dirname.php

Posted: Fri Feb 20, 2004 3:59 pm
by JayBird
i dont want the full server path though, just the path shown in the URL without the filename.

And i don't know what thie filename will be.

Mark

Posted: Fri Feb 20, 2004 5:11 pm
by McGruff
Rgr - define a config constant or something with the absolute path to the web root, then subtract.

Posted: Mon Feb 23, 2004 2:58 am
by JayBird
McGruff wrote:Rgr - define a config constant or something with the absolute path to the web root, then subtract.
How exactly would i do that?

Mark

Posted: Mon Feb 23, 2004 3:59 am
by markl999
$path = dirname($_SERVER['SCRIPT_NAME']);
Did you try that? That will give you the directory relative to the document root.

Posted: Mon Feb 23, 2004 4:37 am
by JayBird
aha!

I missed that one buddy, works a treat!

Thanks

Mark