Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    553
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Read records from file and delete them?

    Is there a way that I can read the first number of records of a file, say 200, and then delete those 200 records? It is a large file, so I would prefer to minimize the amount of file rewriting I do.
    G

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Hi, you can open a file for reading and writing with

    $fp=fopen($file,'r+');

    and traverse the file with fseek() etc, but the best you will be able to do (AFAIK) is overwrite the first $x lines with '' , you will still have say, 200 empty lines at the start of your file.

    unless your file is repressivly large ... and if it is it should not be - then reading the file and rewriting really is the best solution, & as long as you are not echoing the data to screen or anything should be fast enough.

    on *NIX there are the direct i/o functions, dio_truncate() will truncate the file to $x bytes, though from what 'end' I can't say as I have yet to use them.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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