21.3. Cross-Platform Code 3: Path and Line SeparatorsEach OS has a different way of representing path and line separators for files. Unix and modern Mac OS versions use / as a path separator and \n as a line separator, whereas Windows uses \ or / as a path separator and \r\n as a line separator. Just to make things even more confusing, some old Mac OS versions use \r as a line separator and : as a path separator, so all three are different! You can make your life easier by using forward slashes (/) everywhere, because Windows accepts both \ and / as path separators. If you are able to refrain from using OS-specific path names like c:/home/website/index.php, then dovery often, just /home/website/index.php will work just fine everywhere. Line separators are slightly trickier and, if you don't have PHP 5.0.2 or higher, the easiest way to handle them is to put a few lines of code into your shared code library that checks the OS and stores the appropriate line end character in a variableyou can then reuse that variable throughout your other scripts. If you do have PHP 5.0.2 or higher, the constant PHP_EOL is available to you and represents the appropriate newline character for the current OS.
|