[thelist] PHP - get one directory from a path?
Ken Snyder
ksnyder at coremr.com
Tue Dec 19 12:22:25 CST 2006
Try parse_url(). For example:
|if(!defined('PHP_URL_PATH')) define('PHP_URL_PATH', 6);
$path = parse_url('|
http://www.example.com/main/something/inner/',PHP_URL_PATH);
// $path now equals "/main/something/inner/"
--Ken
Stephen Rider Wrote:
> Hi --
>
> I'm trying to figure out a straightforward way to set a PHP variable
> to a particular directory in a path.
>
> For example: I have http://www.example.com/main/something/inner/
> index.php
> The path can change, though. Specifically, the directory "something"
> is arbitrary -- the script could be running in http://www.example.com/
> main/whatever/inner/ and so forth.
>
> When the script runs, I want to set a variable to = "something", or
> whatever that directory name happens to be.
>
> I know how to get the last directory name using dirname() and such,
> but I can't figure out how to get the directory two levels up....
>
> Any ideas? Thanks in advance!
>
> Stephen Rider
>
More information about the thelist
mailing list