$_SERVER["SCRIPT_NAME"]
Moderator: General Moderators
$_SERVER["SCRIPT_NAME"]
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
$_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
- Ixplodestuff8
- Forum Commoner
- Posts: 60
- Joined: Mon Feb 09, 2004 8:17 pm
- Location: Queens, New York
If you know the filename, try this
if not, try somthing like this
Code: Select all
<?php
str_replace ( $filename, '', $_SERVER['SCRIPT_NAME'] );
?>Code: Select all
<?php
$script_name = $_SERVER['SCRIPT_NAME'];
$path = explode ( '/', $script_name );
$counter = count ( $path );
$path[$counter - 1] = NULL;
$output = implode ( '/', $path );
?>See [php_man]pathinfo[/php_man].
Watch out for the dot bug (excerpt from user comments):
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
Last edited by McGruff on Tue Aug 09, 2005 4:46 pm, edited 1 time in total.