[thelist] PHP - get one directory from a path?
Stephen Rider
evolt_org at striderweb.com
Fri Dec 22 17:01:04 CST 2006
On Dec 21, 2006, at 8:02 PM, Phil Turmel wrote:
>> I'm trying to figure out a straightforward way to set a PHP variable
>> to a particular directory in a path.
>>
>> ...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....
>
> I know I'm a little late to this party (business trip), but I
> didn't see
> anything like the one-liner that occurred to me:
>
> $something = basename( dirname( dirname( $_SERVER['PHP_SELF'] )));
THAT was exactly what I was looking for -- a simple drop-in one-
liner. Worked like a champ. I never thought of nesting dirname()s
-- sometimes the easiest solution is staring you in the face. Thanks!
Stephen Rider
More information about the thelist
mailing list