text files ?

A

Anonymous

Guest
I am thinking about making a sort of a stat system but can't figure out how to write to different part of the file and how to read from different parts of the file

do you make a flag like #gotohere1# text and numbers here
#gotohere2# text and numbers here and so on ??

or how do I tackle this little problem? usually you read a file by saying read from start and x amount of bytes ahead or read from where ever you stopped in the file and x amount ahead but how do I tell the script that I want to go to HERE and then read whatever number is there until line end ???

anyone that can help me please?
 
I suggest using mysql database, which will be faster and easier to manage later on.
 
I agree with Garnet, use a database. But I'm curious, what kind of stat system are you referring to??
 
Indeed, it seems like you're taking the most difficult way out. If you really want to do this, I might suggest using file(), which reads the file into an array (one line per element) and thus conveniently gives each line an index. But if you have a big file, this is a poor way to do this. Otherwise, if you can't use a database, I might suggest using XML.
 
aah well it is because we wanted to use it on a smaller system with a click on banner count system with like 4 banners and it seems a little overkill to do it with a database for that little project and I always wanted to find out how to use text files more efficiently.

I know how to use databases already so that is no problem, but when it is so small then it is faster to just add 1 to a number in a text file, atleast when there is only 1 number, now I just want to know how to manage more numbers

how does file work and how does it look at each line and such? and how do I write/read to/from a certain line?
 
You can use a text file and I would use the fopen(), fread(), etc, etc... php commands for reading and writing to the file if that's all you are doing. Search google or http://www.phpfreaks.com for the commands and see the examples associated with them.
 
RTFM.

You'll still have to use fwrite() to write to the file, but once you have the data in a variable, you can just edit the variable and then write the whole thing when you're done.
 
The others are right here, in that databases are alot easier to manage later on. But, if you insist :p on textfiles, the link below has the very basics on reading and writing to them easily. Make sure to check-out the "TEXT WRAPPER CLASS" he gives too, as normally adding-to or deleting set lines that do not fall at the end or beginning of the textfile can be a pain.
http://home.no/apron/english/apron.htm?tut_php
 
The Goto type of directives are the most difficult to handle and manage in any language. For php I don't really remember if there are any such!
And for god sake use a dB, file system sucks in such applications that you are trying to build!
 
Back
Top