I have this code for writing a line to the new.txt file (already consisting of 2 lines), and after that a copy (backup) of this txt content to the new tmp.txt file but fread () does not skip the new line from the new file. txt to copy to tmp.txt tmp.txt suppose you have 3 lines inside, but there is no new line added.
$File ="new.txt"; $File2="tmp.txt"; //write into file $handle = fopen ($File, 'a') or die("Cannot open File"); fwrite($handle,"some string"); fclose($handle ); //copy file $handle2= fopen ($File, 'r') or die("Cannot open File"); $content = fread($handle2, filesize($File)); fclose($handle2); $handle3 = fopen ($File2, 'w') or die("Cannot open File"); fwrite($handle3,$content); fclose($handle3 );
source share