PHP - Using a text file as a database?

Jonathan

New member
Ok, I have an IRC bot made from PHP (if you don't know what IRC is, it's a chat)
I'm working on a command where users can enter their bday and it stores them in a text file, I'm not going to explain the way the bot works, but I'll keep it simple ;)

ok let's say someone typed !bday
this would make the bot search the text file for the line containing their nick, and display it.
sooo let's say that when someone typed !bday... $nick is their nick.

it would need to search the text file for a LINE containing their $nick and display the whole LINE.
for example: "xx Days xx Minutes xx Seconds until $nick bday!"

ok, that's the first command I need help with.. the next command I need help is storing the bday.
let's say the user typed !addme 1/1/2012
and lets say that the part "1/1/2012" is the input and the input is $input

there's 3 things I need it to do....
I need it to first check if they entered it correctly.. meaning that if the input doesn't match the pattern: mm/dd/yy it returns false.

the second thing I need to do is change the $input to something.
because in order for my timer code to work properly, the format needs to be like this..
if the user inputs: 1/12/2010
it should be changed to: 1 December 2010

now for the third thing...
there's a special way I need it to submit..
for example, when someone adds them self, it puts their bday on a line in the text file.
BUT if their $nick already exists in a line of the text file, it should delete the line and re-add their bday.
and if this happens it needs to echo something different.. like "Success, updated!" or something.

ok I think you get the idea.. please help me, I am sort of novice at PHP so I don't know how to do this..
Edit: for the second thing (changing the mm/dd/yy to something else) I think I have it figured out myself.

str_replace('2', 'February', str_replace('1', 'Januauary', str_replace('/', ' ', $input))); etc etc

or would there be a better day?
Edit again: no. my method wouldn't work :( because then 1/1/2010 would result in something like Januauary Januauary 20Januauary0
lol.
 
Back
Top