From 54088daa673200afeb7ad53bb2b8058e1c5f2e17 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sat, 20 Apr 2013 16:08:26 +0100 Subject: [PATCH] Replace \r\n and \r line endings with \n To set it to Unix as the default. Opening files with \n line endings in relatively modern programs will know to use line breaks here if not the native OS preference --- lib/file-control.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/file-control.php b/lib/file-control.php index bf1e8f5..fe1572c 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -252,7 +252,12 @@ if ($_GET['action']=="save") { $filemtime = $serverType=="Linux" ? filemtime($file) : "1000000"; if (!(isset($_GET['fileMDT']))||$filemtime==$_GET['fileMDT']) { $fh = fopen($file, 'w') or die("Sorry, cannot save"); - fwrite($fh, $_POST['contents']); + // replace \r\n (Windows) and \r (old Mac) line endings with \n (Linux) + $contents = $_POST['contents']; + $contents = str_replace("\r\n", "\n", $contents); + $contents = str_replace("\r", "\n", $contents); + // Now write that content, close the file and clear the statcache + fwrite($fh, $contents); fclose($fh); clearstatcache(); $filemtime = $serverType=="Linux" ? filemtime($file) : "1000000";