Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

text files ?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

text files ?

Postby Godiwa » Mon Aug 25, 2003 8:52 am

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?
Godiwa
New php-forum User
New php-forum User
 
Posts: 40
Joined: Wed Mar 05, 2003 5:55 am

Postby Joan Garnet » Mon Aug 25, 2003 9:41 am

I suggest using mysql database, which will be faster and easier to manage later on.
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Postby tryton » Mon Aug 25, 2003 10:57 am

I agree with Garnet, use a database. But I'm curious, what kind of stat system are you referring to??
User avatar
tryton
New php-forum User
New php-forum User
 
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze

Postby swirlee » Mon Aug 25, 2003 12:20 pm

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.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Godiwa » Thu Aug 28, 2003 2:00 am

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?
Godiwa
New php-forum User
New php-forum User
 
Posts: 40
Joined: Wed Mar 05, 2003 5:55 am

Postby tryton » Thu Aug 28, 2003 6:42 am

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.
User avatar
tryton
New php-forum User
New php-forum User
 
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze

Postby swirlee » Thu Aug 28, 2003 6:53 am

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.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby cw4908 » Mon Sep 08, 2003 6:40 pm

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
cw4908
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun Aug 31, 2003 3:06 am

file

Postby ruturajv » Mon Sep 08, 2003 10:43 pm

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!
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.