I know how to write to a txt file, but I want to put the new data to the beginning of the txt file (in front of existing data) not at the end. So the current updates will be at the top.
Thanks!
I know how to write to a txt file, but I want to put the new data to the beginning of the txt file (in front of existing data) not at the end. So the current updates will be at the top.
Thanks!
Last edited by M2com; 07-27-2011 at 10:51 PM.
PHP Code:<?php
$lines = file('my_text_file.txt');
$fopen = fopen('my_text_file.txt', 'w+');
fwrite( $fopen, "A new line at the top.\r\n");
foreach ($lines as $line) { fwrite( $fopen, $line); }
fclose($fopen);
?>
Focus on Function Web Design
Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps
Thanks for the reply! Though when I used your script, it gave me this error: fwrite(): 2 is not a valid stream resource...
Thanks again!
Never mind! Fixed it!
Thanks!
Bookmarks