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

Stephen Rider evolt_org at striderweb.com
Wed Dec 20 16:14:30 CST 2006


On Dec 20, 2006, at 10:20 AM, Simon 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
>
> How about this:
> <?php
>      $parts = explode( '/', $_SERVER['SCRIPT_NAME'] );
>      $something = $parts[ (count( $parts ) - 3 ) ];
>
>      echo "something == $something";
> ?>

That looks like exactly what I was looking for, though I may stick  
with $_SERVER['PHP_SELF']

Much thanks to all who responded.

Stephen



More information about the thelist mailing list