I'm using a txt file as a database for a project. I read it, convert it to an array with a delimiter, and process the arrays (as id, title, text..)
But now, i will have to add large chunks of text in my text database, and i'm a litle concerned, that in time, my file will become large, and i will have memory issues, and my server provider won't be happy :)
So far, my idea is to split my database to two files: one with the id and the text, and a second with the id and the title - and the line that the first line was saved:
first file:
id|text
15|Lorem ipsum dolor sit amet, consectetur adipiscing elit...
second file:
id|title|line
15|Lorem ipsum|2
..and to find a way to read the first (large) file without parsing it to arrays, just go to the line i get from the second file, and then parse it to arrays to use it with my code.
My two problems:
One, i didn't find out (yet) how to get a line number in return when i append a line to a text file. One idea is to read again the file, and count it's lines, but i thing this will not help my with my memory leak fears :)
Two, even if i have the line number, my option is to read the big file line by line, and stop when the integer stops at my line. Is this the best way i can do it?
Thanks for your time, i hope my poor english and PHP knowledge made any sense :)
--
TL;DR: i want to parse a large txt file, and looking for help to a) know the line when i append something to it, and b) to go and read that line, without reading all the file.