Results 1 to 10 of 10

Thread: flat file reading backwards

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181

    flat file reading backwards

    hi

    i'm appending some text to a flat file (.txt), but when i read it, i only want to read the last 5 lines. i can read the file fine forwards.

    is there a way to append the text to the top, or is there a way to read it backwards (last text first)

    --770

  2. #2
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    how are you appending to it? if you jsut open it and write to it I think by default it goes to the end.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    yes, i'm just opening it and i know by default it puts it at the bottom, but is there a way to just get the bottom 5 lines??


    --770

  4. #4
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yes you can, but if you get just the 5 bottom lines then it will erase all the others lines.

    once you find the amount of lines you can subtract 5 and then just delete the rest of them. can't imagine why you want only the last five lines if you keep adding to it. also it depends on what the seperater is, a , or a ; or a |

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    well it's for a shout box. i could use mysql but i don't have it installed.. i'm running the server off my computer.

    but i don't have to delete the other lines do i .. i just have to read the file to get the number of lines, and then read it again to get the last 5..

    but i'm not sure how to code that.. (to get the number of lines and to get the total lines - 5) appreciate any help..

    thanx

    --770

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    what are you going to do with those five lines? when you get them

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    well i just want to post the latest 5 shouts...

    i know this would be a lot easier with mysql....but my only concernt is when i move the site to a server, will i be able to copy the database to their server? because i don't want to loose the info.

    --770

  8. #8
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yes you can backup db or copy the db to the new server.

    to find the total length of a file (total lines ) you do this

    $fileread = fopen("file.txt", "r");
    $arrlen = count($fileread);

    count will count all the lines. tha tshould be wha tyou are looking for. or you could put each line into an array and count it that way.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2001
    Location
    Ottawa, Canada
    Posts
    181
    thanx.....i'll use that for now

    but i also downloaded mysql and installed it.....but i was wondering if there is any graphical utility i could you to add/modify tables quickly. i've used myphpadmin or something like that on a server, but i can't find one i can you on my computer with iis.....

    i tried the one off the mysql website mysql control center, but that was terrible..are they anyothers that are better??

    thanx

    --770

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    you can download phpMyAdmin for free here

    http://www.phpwizard.net/projects/phpMyAdmin/

Posting Permissions

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



Click Here to Expand Forum to Full Width