phppaper Posted March 24, 2011 Share Posted March 24, 2011 I have any array with name, gender , age I want to write into a csv which already contains many records line by line, I would like to write the array elements into the csv as a line line from the bottom without overwritten the whole csv. How to do so? Thanks Link to comment https://forums.phpfreaks.com/topic/231573-how-to-write-array-into-csv-last-line-without-overwritten-the-whole-csv/ Share on other sites More sharing options...
MrXHellboy Posted March 24, 2011 Share Posted March 24, 2011 What's your code right now ? Link to comment https://forums.phpfreaks.com/topic/231573-how-to-write-array-into-csv-last-line-without-overwritten-the-whole-csv/#findComment-1191632 Share on other sites More sharing options...
QuickOldCar Posted March 24, 2011 Share Posted March 24, 2011 Here's code to show and write last line to a text file, the commented one is to replace the entire files contents. <?php //read a file $my_file = "file.txt"; if (file_exists($my_file)) { $data = file($my_file); $total = count($data); echo "<br />Total lines: $total<br />"; foreach ($data as $line) { echo "$line<br />"; } //add a new line to end $write = fopen($my_file, 'a+'); $message = "I just added this line\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\r\n"; fputs($write, $message); fclose($write); */ } else { echo "No file to display"; } ?> Link to comment https://forums.phpfreaks.com/topic/231573-how-to-write-array-into-csv-last-line-without-overwritten-the-whole-csv/#findComment-1191710 Share on other sites More sharing options...
phppaper Posted March 25, 2011 Author Share Posted March 25, 2011 Thanks alot, just what I need Link to comment https://forums.phpfreaks.com/topic/231573-how-to-write-array-into-csv-last-line-without-overwritten-the-whole-csv/#findComment-1192016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.