Jpoel Posted January 21, 2008 Share Posted January 21, 2008 Hi again Heres the deal. I have a text file, which is constantly having things written to it example: the text file is in the form of: ,James:1: ,Kimberley:2: ,Bob:3: ,Joe:4: ,John:5: every now and again, a new value is inserted into the end of the text file, example, Josh is added: ,James:1: ,Kimberley:2: ,Bob:3: ,Joe:4: ,John:5: ,Josh:6: However, when this php script is used to add a new value to the end of the text file, and the length of the file is 30 lines long in length, what i want is for the php script to remove the first line, and add the new value to the end, to maintain the 30 line limit Does anyone know how i could do this? Thanks. PS I use Fwrite and Fread to write to the text file. Link to comment https://forums.phpfreaks.com/topic/87132-solved-limiting-a-text-file-to-a-certain-number-of-lines/ Share on other sites More sharing options...
KrisNz Posted January 21, 2008 Share Posted January 21, 2008 You can use file() to read the file into an array, where each line is an entry in the array. If count() of array == 30 then array_shift() to remove the first entry, implode() the array back into a string, append your new line, rewrite the file. Link to comment https://forums.phpfreaks.com/topic/87132-solved-limiting-a-text-file-to-a-certain-number-of-lines/#findComment-445653 Share on other sites More sharing options...
Jpoel Posted January 22, 2008 Author Share Posted January 22, 2008 You can use file() to read the file into an array, where each line is an entry in the array. If count() of array == 30 then array_shift() to remove the first entry, implode() the array back into a string, append your new line, rewrite the file. thanks KrisNz, that did the job Link to comment https://forums.phpfreaks.com/topic/87132-solved-limiting-a-text-file-to-a-certain-number-of-lines/#findComment-446347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.