Altec Posted January 10, 2009 Share Posted January 10, 2009 I'm writing a very small test script to get familiar with flat file database techniques. In this case I'm using just a text file and plan on using a pipe ( | ) to separate my fields. However, I'm interested in limiting how many rows are stored. For example, if I wanted to limit how many comments are stored, and each subsequent comment made "pushes" the oldest comment out, how would I do this? I should also mention I know the basics of reading and writing to files. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 10, 2009 Share Posted January 10, 2009 use \x01 to seperate your fields, you will never get someone to input \x01 and if they do.. just do str_replace("\x01","",$inputText); because I use | alot lol even outside of programming.. and the best method I guess.. would be to read out your file.. append your new input text to the array containing all other comments.. get the last 10 elements of the array, then clear the text from the file then put the 10 elements you've gotten back into the file.. Quote Link to comment Share on other sites More sharing options...
Altec Posted January 10, 2009 Author Share Posted January 10, 2009 Hmm... I ran across this snippet: $lines = file("$savefile"); fwrite($openfile, "$data "); for ($i = 0; $i < $maxlines; $i++) { @fwrite($openfile, "$lines[$i]"); } What does the for loop do? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.