helloise Posted April 21, 2011 Share Posted April 21, 2011 how do i do this please?? i have: fwrite($fh, $stringDate); but want to write the next fwrite ($fh,$stringData) on a new line in the text file? thank you Link to comment https://forums.phpfreaks.com/topic/234317-fwrite-a-new-line/ Share on other sites More sharing options...
QuickOldCar Posted April 21, 2011 Share Posted April 21, 2011 try that out and see the results. the commented out version would overwrite the file <?php //read a file $my_file = "samplefile.txt"; if (file_exists($my_file)) { $data = file($my_file); $total = count($data); echo "<br />Total lines: $total<br />"; foreach ($data as $line) { $line = trim($line); echo "$line<br />"; } //add a new line to end $write = fopen($my_file, 'a+'); $message = "added a new line here\r\n"; fputs($write, $message); fclose($write); /* //note the w, this will overwrite the entire contents $write = fopen($my_file, 'w'); $message = "I just added this line and overwrote the file\r\n"; fputs($write, $message); fclose($write); */ } else { echo "No file to display"; } ?> Link to comment https://forums.phpfreaks.com/topic/234317-fwrite-a-new-line/#findComment-1204372 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.