Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

PHP: OS Appropriate Directory Separator

Posted on 2011-03-16
2
278 Views
Last Modified: 2012-05-11
I want $SystemSlash to either be / or \ depending on the operating system.

How can I make $SystemSlash be the appropriate directory separator for the operating system used?
<?php

echo $SystemSlash . 'path' . $SystemSlash . 'to' . $SystemSlash . 'my/file.php';

?>

Open in new window

0
Comment
Question by:hankknight
2 Comments
 
LVL 2

Expert Comment

by:k_romych
ID: 35149656
if (strpos($_SERVER['DOCUMENT_ROOT'],'/')){$SystemSlash='/';}else{$SystemSlash='\\' ;}
0
 
LVL 8

Accepted Solution

by:
Rik-Legger earned 500 total points
ID: 35149811
Or even easier just use the constant name DIRECTORY_SEPARATOR:

<?php

echo DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'to' . DIRECTORY_SEPARATOR . 'my/file.php';

?>

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question