#20875 [Com]: function to fix path names
| From: | lonely dot 16 at hotmail dot com | Date: | Wed, 17 Feb 2010 06:48:59 +0000 |
| Subject: | #20875 [Com]: function to fix path names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-147748@lists.php.net to get a copy of this message | ||
ID: 20875
Comment by: lonely dot 16 at hotmail dot com
Reported By: briantmeyer at earthlink dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: win2000
PHP Version: 4.3.0RC2
New Comment:
Hey. Hello. I`m glad that I found this site. greetings. Help me! Could
you help me find sites on the: Fox woods casino entertainment. I found
only this - <a
href="http://www.justiceplanbook.com/Members/CasinoEntertainment/reno-casino-entertainment">reno
casino entertainment</a>. With his casino in different everything and
party, trump has located in tumbling the trump bingo on a whole gaming
of ones, casino entertainment. Arthur else has been using a viable fun
casino company for over 15 goods, and has much designed playing compared
in larger desires, casino entertainment. With respect :confused:,
Acantha from Tonga.
Previous Comments:
------------------------------------------------------------------------
[2002-12-07 04:26:31] briantmeyer at earthlink dot com
It would be nice to have a generic function to clean up
paths so they will work on all platforms. Similar in scope
to addslashes but focusing on the issues of paths and cross
platform compatibility of scripts.
Researhing this i only found http://bugs.php.net/
bug.php?id=10916 was related but that was from a long time
ago. There also seems like there are equivalents in other
languages (VMS, PERL)
I know there is already much code for this out there,
because everyone that writes cross platform has to have a
solution, and that all of it is fairly simple to create as
needed if you pay attention to it revolving mainly around
"/" changing into "\" and vice versa.
However, being relatively new to php, it seems that this
type of code is overly prevalent and would be the perfect
use for a function, where you pass it the wrong unix/
windows path and it returns the path for the platform you
are installed on, or even semi-intelligently figure out
what you really meant.
It should be added to the core distribution, due to it's
purpose to allow greater collaboration between coders
across different installations, and the extent of use in a
single application would not warrant using a function in
most cases.
Isn't it difficult to adequately debug for developers that
are only on a single platform without such a tool? They'll
have no idea until they test it. Code related to this issue
is in all the opensource projects, but only in one or two
places per project and was probably only added upon someone
trying to use on the wrong platform.
It also seems like this could allow the php language to
elegantly handle variations with other separators such as
the older mac ":". For instance, XP changed the hard drive
letter from the traditional c:\ to d:\ or whatever the last
drive is. I am sure that requires some script tweaking. As
changes occur, they can happen globally across the entire
php community allowing older scripts that use this to keep
on working.
This would make code generally more cross platform without
the necessary "if platform, then this path" that needs to
be tested and debugged on both platforms. It is, as i am
thinking of it, a very simple thing needed more for
compatibility between installs than anything else, It seems
like this is the only real area of code difference between
unix and windows machines and working solely with the
windows platform, i already know my scripts will break on
the other platforms with my use of "\\". Adoption of a
function as such would allow me to develop on windows, and
deploy (or share) on unix without as many issues(or vice
versa). It also would allow me to use "/" as instead of "\\
" in my paths which seem to look more "right" to me and
would make my scripts the same as the unix/mac/linux
developer. (It gets hard to keep track of which are escapes
and which are slashes sometimes). It also might allow the
distribution php.ini files to use cross platform paths that
work asis on both platforms if all paths are run through
this function as they are read from this file.
Having a prepend option that would allow easy access to get
the path of folders that change from machine to machine
without extra coding. This has always been a great feature
of applescript and should find it's way into php. The web
root folder, include folders, OS directory, php directory,
or paths set in php.ini. Perhaps even allow developers to
add paths to php.ini that configure their products.
fixpath($path, [prepend], [append], [unix/pc/html
override])
fixpath($path, "c:/", "", "PC") // as opposed to "c:\\"
makes easier to read
fixpath($path, "INCLUDEFOLDER", "", "PC") // use of
keyword and returns windows path
Basically it would
a. determine platform
b. convert path "/" to "\" or "\" to "/" b
ased on platform, if wrong
c. perhaps add a c:\ or other
path information to the beginning as needed
c. re
move any "//" due to
$
rootdir = "/bin/";
$thisdir = $rootdir."/somedir/
"; // or other platform restrictions
(yes i know, dumb
mistake but still nice to elegantly fix)
d. test to se
e if file exists, perhaps looking through include fol
ders
e. have a prepend/append string
f. override path wi
th platform
g. ex
p
and strings like .. to enclosing folder path
h. fix invali
d characters on platform --- (target file after file upload)
i. have keywords that convert to local system paths ww
root/currentpath/domain root (http://www.url.com/)/or p
hp.ini settings added by user.
j. resolve an Alias/S
hortcut.
and would return a valid absolute path to a fi
le
This seems like a very easy and fast thing to code fo
r the most part, even for me with m
y
current limited kno
w
ledge of php. I also w
o
uld make the languge better, easier, and more elegant.
How
would something like this get into the core dis
t
ribution?
What would keyword
s be, what needs to be access
ed? Is there already an accepted Syntax
that should be used for keywords this function accesses.
Are there other path related platform issues?
Are there folder paths that are hard to access?
Is the code for the functions in the core distribution
written in php or in a higher level language?
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20875&edit=1