function trimmer($realFileString2 = "test.txt", $tempFileString2 = "test2.txt") { //part 1 $myfile = fopen($realFileString2, "r") or die("Unable to open file!"); $tempFile = fopen($tempFileString2, "w") or die("Unable to open file!"); while (!feof($myfile)) { $word = ltrim(fgets($myfile)); fwrite($tempFile, $word); } fclose($myfile); fclose($tempFile); //part 2 $myfile = fopen($tempFileString2, "r") or die("Unable to open file!"); $tempFile = fopen($realFileString2, "w") or die("Unable to open file!"); while (!feof($myfile)) { $word = trim(fgets($myfile)) . "\n"; fwrite($tempFile, $word); } fclose($myfile); fclose($tempFile); eraseLastLineBreak($realFileString2); }
} else { $word1 = fgets($myfile); $word2 = fgets($myfile); $word3 = fgets($myfile); $word1 = $_REQUEST[$name_wordEdit1]; $word2 = "\n" . $_REQUEST[$name_wordEdit2]; $word3 = "\n" . $_REQUEST[$name_wordEdit3] . "\n"; fwrite($tempFile, $word1); fwrite($tempFile, $word2); fwrite($tempFile, $word3); } } fclose($myfile); fclose($tempFile); //new 8/12/2015 eraseLastLineBreak($tempFileString); $myfile = fopen($realFileString, "w") or die("Unable to open file!"); $tempFile = fopen($tempFileString, "r") or die("Unable to open file!"); // echo "<H1> JMLKJM 1 </H1>"; $u = -1; while (!feof($tempFile)) { $u = $u + 1; $word1 = fgets($tempFile); $word2 = fgets($tempFile); $word3 = fgets($tempFile); fwrite($myfile, $word1); fwrite($myfile, $word2); fwrite($myfile, $word3); } // echo "<H1> JMLKJM 2</H1>"; fclose($myfile);