Sorry if I don't make this too clear, what I'm doing is creating a text based adventure game in PHP, a lot like Colossal Cave.
I do not want to recreate my databases for every user so I hoping to write all the user date into a file and read variables from it when I require.
For example the file would be like this:

HP: 100
Room: 4
Item: torch
Item: batteries

e.t.c.

I know a tiny bit about fopen, fseek and fwrite but I do not know how I would go about extracting the text as variables into PHP and writing them back in.

Any help would be gratefully recieved
Daryll

Show us the code you have and we'll help you from there.

ideally you would want to use a database.


but if you really want to use a flat file, this is how I would do it.

to "write"
put the elements in an array or class.

serialize them. http://php.net/manual/en/function.serialize.php

the use file_put contents. http://php.net/manual/en/function.file-put-contents.php

to "read"

read the file http://www.php.net/manual/en/function.file-get-contents.php

unserialize them http://www.php.net/manual/en/function.unserialize.php

Sorry I cant show my code as all I have at the moment is my databases, it works for a single user and I see this way most fit to implement multi-user into the game.

In your opinion would it be a better option to use the flat file and draw the variables from that when needed or write a script to create a new database and tables for each user?

I thought about using a database to store the information but for a single user it requires 6 tables in the database to fully normalise it, therefore I did not think it would practical to do this for the user base I intend to test on in the Uni.

Kireol thank you for that, I will look into those options for now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.