What are the best practices for dealing with directory separators in PHP to ensure cross-platform compatibility?

When dealing with directory separators in PHP to ensure cross-platform compatibility, it is best to use the DIRECTORY_SEPARATOR constant provided by PHP. This constant will automatically resolve to the correct directory separator based on the operating system the code is running on. By using this constant, you can write code that works seamlessly on both Windows and Unix-based systems.

// Using DIRECTORY_SEPARATOR constant to ensure cross-platform compatibility
$filePath = 'path' . DIRECTORY_SEPARATOR . 'to' . DIRECTORY_SEPARATOR . 'file.txt';