Results 1 to 4 of 4

Thread: Put new data in front of existing data

  1. #1
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Exclamation Put new data in front of existing data

    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.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    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

  3. #3
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default

    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!

  4. #4
    Join Date
    Jul 2011
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default

    Never mind! Fixed it!

    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •