Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #16375

Re: Handling parts of paths and directory names in PHP

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.php
Subject Re: Handling parts of paths and directory names in PHP
Date 2016-02-08 21:27 +0000
Organization A noiseless patient Spider
Message-ID <87ziva99kt.fsf@bsb.me.uk> (permalink)
References <n92n9n$3gq$1@dont-email.me> <87io22kgfe.fsf@bsb.me.uk> <slrnnbhq6b.us5.hellsop@nibelheim.ninehells.com>

Show all headers | View raw


"Peter H. Coffin" <hellsop@ninehells.com> writes:

> On Fri, 05 Feb 2016 21:15:01 +0000, Ben Bacarisse wrote:
>> James Harris <james.harris.1@gmail.com> writes:
>>
>>> Do you guys have any generic recommendations on how to store paths
>>> based on your experience of handling paths in PHP?
>><snip>
>>> When handling such path parts as strings there are issues over whether
>>> to store slash characters at the start and end of a part or whether to
>>> add the slash when they are combined. Related, is avoiding a resultant
>>> path having a double slash (i.e. //) at any point.
>>
>> I would not store the slashes.  When I store paths as an array of
>> components I store absolute paths with a "" as the first one.  Then the
>> full path is just a join operation.
>
> Funny, that's almost exactly the opposite of how I look at it. To me,
> the vast, vast majority of the time, I'm always only going to be dealing
> with the full path anyway, because mostly I care about the thing at the
> end of the path, and don't really give a damn what the path itself is.
> So spending time writing, then running, code to assemble and break down
> paths every time I want to access the thing at the end just seems to
> gain me very little.

Quite.  I think you missed the conditional mood of "I would ...".  I
would not store the slashes in the situation the OP described where,
apparently, it is worth breaking it down.  As you say, that vast
majority of the time there is no need.

But maybe it's worth asking "do you really need to do this?".

> And the majority of the time that I care about
> anything other than just the target at the end, what I care about is the
> penultimate part, the directory the thing is in. And there's already a
> built-in function for getting that, that I don't have to write and is
> probably more efficient than I could do in PHP itself anyway.

I'm not sure in this case, but James Harris usually posts after checking
documentation and so on, so it's likely he knows the standard path
functions.

-- 
Ben.

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Handling parts of paths and directory names in PHP James Harris <james.harris.1@gmail.com> - 2016-02-05 17:51 +0000
  Re: Handling parts of paths and directory names in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-05 21:15 +0000
    Re: Handling parts of paths and directory names in PHP James Harris <james.harris.1@gmail.com> - 2016-02-05 22:28 +0000
    Re: Handling parts of paths and directory names in PHP "Peter H. Coffin" <hellsop@ninehells.com> - 2016-02-08 13:13 -0600
      Re: Handling parts of paths and directory names in PHP Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-08 21:27 +0000
  Re: Handling parts of paths and directory names in PHP Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-09 00:09 +0100
    Re: Handling parts of paths and directory names in PHP Jerry Stuckle <jstucklex@attglobal.net> - 2016-02-08 19:34 -0500

csiph-web