Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16361 > unrolled thread
| Started by | James Harris <james.harris.1@gmail.com> |
|---|---|
| First post | 2016-02-05 17:51 +0000 |
| Last post | 2016-02-08 19:34 -0500 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.lang.php
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
| From | James Harris <james.harris.1@gmail.com> |
|---|---|
| Date | 2016-02-05 17:51 +0000 |
| Subject | Handling parts of paths and directory names in PHP |
| Message-ID | <n92n9n$3gq$1@dont-email.me> |
Do you guys have any generic recommendations on how to store paths based on your experience of handling paths in PHP? The main choices seem to be to store a path as a string or as an array of directory names, the latter requiring an implode/join operation to convert to a string. I have to store a path as multiple parts, each of which could have multiple levels of directory. To make up an example, there could be these parts of a single path /var/www/region /site/subsite/partition/ /folder/subfolder filename Just about the only unusual operation I need to carry our is to match the last part of paths based on prefixes. But there will be the normal taking apart and putting paths together, and some parts with need to be visible to users such as /folder/subfolder/filename. Parts prior to that will be invisible to users. In a visible path, /folder will appear to be in the root as far as users are concerned. 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. These are mainly standard programming issues. I just wondered if you guys had come up with a consistent approach or whether you approach each problem separately. So, any recommendations as to whether to store each part of a path as a string or an array in PHP? James
[toc] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-02-05 21:15 +0000 |
| Message-ID | <87io22kgfe.fsf@bsb.me.uk> |
| In reply to | #16361 |
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. > These are mainly standard programming issues. I just wondered if you > guys had come up with a consistent approach or whether you approach > each problem separately. > > So, any recommendations as to whether to store each part of a path as > a string or an array in PHP? If you think it's worth it, wrap it in a class so you can easily change your mind about that. (I presume there's a typo in the question, though. If not, I've got the wrong end of the stick again.) -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | James Harris <james.harris.1@gmail.com> |
|---|---|
| Date | 2016-02-05 22:28 +0000 |
| Message-ID | <n937hv$4cg$1@dont-email.me> |
| In reply to | #16362 |
On 05/02/2016 21:15, 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. OK. >> These are mainly standard programming issues. I just wondered if you >> guys had come up with a consistent approach or whether you approach >> each problem separately. >> >> So, any recommendations as to whether to store each part of a path as >> a string or an array in PHP? > > If you think it's worth it, wrap it in a class so you can easily change > your mind about that. (I presume there's a typo in the question, > though. If not, I've got the wrong end of the stick again.) A class is a good idea. As you suggest, it would be a bit of work to write all the methods but it would allow the implementation to be changed. I'll give it some thought. I read through the original query and didn't see a typo but your comments answered my question. Thank you. James
[toc] | [prev] | [next] | [standalone]
| From | "Peter H. Coffin" <hellsop@ninehells.com> |
|---|---|
| Date | 2016-02-08 13:13 -0600 |
| Message-ID | <slrnnbhq6b.us5.hellsop@nibelheim.ninehells.com> |
| In reply to | #16362 |
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. 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. -- 34. I will not turn into a snake. It never helps. --Peter Anspach's list of things to do as an Evil Overlord
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-02-08 21:27 +0000 |
| Message-ID | <87ziva99kt.fsf@bsb.me.uk> |
| In reply to | #16374 |
"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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2016-02-09 00:09 +0100 |
| Message-ID | <2226079.Z0oZMHuoqP@PointedEars.de> |
| In reply to | #16361 |
James Harris wrote: > Do you guys have any generic recommendations on how to store paths based > on your experience of handling paths in PHP? > […] > So, any recommendations as to whether to store each part of a path as a > string or an array in PHP? Yes and yes. <http://www.catb.org/esr/faqs/smart-questions.html> -- PointedEars Zend Certified PHP Engineer <http://www.zend.com/en/yellow-pages/ZEND024953> | Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2016-02-08 19:34 -0500 |
| Message-ID | <n9bc1u$8t5$1@jstuckle.eternal-september.org> |
| In reply to | #16376 |
On 2/8/2016 6:09 PM, the troll Thomas 'Pointed Head' Lahn wrote: > James Harris wrote: > >> Do you guys have any generic recommendations on how to store paths based >> on your experience of handling paths in PHP? >> […] >> So, any recommendations as to whether to store each part of a path as a >> string or an array in PHP? > > Yes and yes. > > <http://www.catb.org/esr/faqs/smart-questions.html> > Trolling again, I see. The question is very clear to everyone except you. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web