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
This commit is contained in:
Matt Pass
2013-04-20 16:08:26 +01:00
parent 169312f021
commit 54088daa67

View File

@@ -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";