Re: trim last folder in a path
- From: "Andrew @ Rockface" <andrew@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 28 Jun 2005 06:29:48 +0000 (UTC)
In news:HeidnTcRG8UFIV3fRVn-1w@xxxxxxxxxxxxx,
paul <paul@xxxxxxx> wrote:
> Philip Olson wrote:
>> Or simply check out the dirname() and basename() functions. Okay,
>> basename() is what you want but they both are useful :-)
>>
>
> Thanks but not what I needed this time. I needed the final folder in a
> long path as retrieved by getcwd() 'GET Current Working Directory'.
>
> basename() returns the file name minus extension... which I can use
> elsewhere in this script as it happens!
Basename will still work even if the last part of the path is a directory.
Taken from the basename() manual page:
antrik at users dot sf dot net
15-Nov-2004 06:40
When using basename() on a path to a directory ('/bar/foo/'), the last path
component ('foo') is returned, instead of the empty string one would expect.
(Both PHP 4.1.2 and 4.3.8 on GNU/Linux.) No idea whether this is considered
a bug or a feature -- I found it extremely annoying. Had to work around
using: <?php $file=substr($path, -1)=='/'?'':basename($path) ?> Watch out!
--
Andrew @ Rockface
np: Blind Willie Johnson - Take Your Stand
www.rockface-records.co.uk
.
- References:
- trim last folder in a path
- From: paul
- Re: trim last folder in a path
- From: Simon Bridgewater
- Re: trim last folder in a path
- From: paul
- Re: trim last folder in a path
- From: Philip Olson
- Re: trim last folder in a path
- From: paul
- trim last folder in a path
- Prev by Date: Re: trim last folder in a path
- Next by Date: Re: trim last folder in a path
- Previous by thread: Re: trim last folder in a path
- Next by thread: Re: trim last folder in a path
- Index(es):
Relevant Pages
|