What potential issues can arise from incorrect usage of \n and \r in PHP data?
Incorrect usage of \n and \r in PHP data can lead to formatting issues, especially when dealing with text files or when displaying data on a webpage. For example, using \n instead of \r\n when writing data to a file on Windows can result in the file appearing as a single line of text. To solve this issue, it is important to use the correct line endings (\r\n for Windows, \n for Unix) based on the platform where the data will be used.
// Correctly handle line endings based on the platform
$data = "Line 1\r\nLine 2\r\nLine 3";
$file = fopen("data.txt", "w");
fwrite($file, $data);
fclose($file);