Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the point of using DIRECTORY_SEPARATOR over "/" in php

Why would I choose to use . DIRECTORY_SEPARATOR . instead of . "/" . ?

My initial thought was that there could be a different separator instead of a slash, but if I'm designing, say, a Wordpress Plugin, can I not assume that there is always a / separating two folders?

like image 878
Jacob Raccuia Avatar asked Dec 04 '25 05:12

Jacob Raccuia


1 Answers

If the application is going to run on a variety of operating systems then the directory won't always be a forward slash. It's a backwards slash on Windows for example.

A similar case is new lines. It's \n on *nix, \r\n on Windows, etc. That's why there is PHP_EOL.

like image 187
John Conde Avatar answered Dec 07 '25 03:12

John Conde