[thelist] PHP - get one directory from a path?

Matt Warden mwarden at gmail.com
Tue Dec 19 12:45:22 CST 2006

On 12/19/06, Stephen Rider <evolt_org at striderweb.com> wrote:
> 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.

$parts = explode('/', $_SERVER['PHP_SELF']);

Matt Warden
Cleveland, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list