TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-18-2008, 12:51 AM   #1 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
TerrorRonin is on a distinguished road
Default DIRECTORY_SEPARATOR not necessary

In attempting to write cross-platform, portable PHP engine, I was using PHP's DIRECTORY_SEPARATOR constant to write path strings(eg ".." . DIRECTORY_SEPARATOR . "foo.php", because the proper way to write it in Windows would be "\" while in Unix it would be "/".

Well, an engineer from php.net pointed out to me that, and a few other programmers confirmed that using that constant is completely unnecessary. As long as you use the forward slash (/), you'll be fine. Window's doesn't mind it, and it's the best for *nix operating systems.

(Note that DIRECTORY_SEPARATOR is still useful for things like exploding a path that the system gave you.)

Hope this is useful to people.
TerrorRonin is offline  
Reply With Quote
The Following 4 Users Say Thank You to TerrorRonin For This Useful Post:
Alan @ CIT (03-18-2008), DeMo (03-18-2008), sjaq (03-18-2008), Wildhoney (03-18-2008)
Old 03-18-2008, 01:39 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Very useful. Thanks Robin! It leaves me astonished how PHP cannot stick to naming conventions even with their constants. I have to admit, I've not heard of the DIRECTORY_SEPARATOR before -- my bad! However, if they'd prepended it with PHP_, I may have stood a chance at finding it. That way it would have appeared in the auto-complete list on the day I found PHP_EOL.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 03-18-2008, 07:31 PM   #3 (permalink)
The Acquainted
 
sjaq's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
sjaq is on a distinguished road
Default

But can you use both of them in one request? Because I always use getcwd() which returns something like this in Windows: C:\Bla\Bla and if I append my path without using DIRECTORY_SEPARATOR I will get something like this: C:\Bla\Bla/linux/style/path but will that work?
sjaq is offline  
Reply With Quote
Old 03-19-2008, 09:53 PM   #4 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Yes, it will. *nix paths (and mixed) are compatible with windows, but the inverse is not true. *nix systems will fail to resolve a path given as "\usr\bin", for instance.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:12 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design