Hello everybody,
What I want to do is create a log file that is kinda like a history log and be able to read from it later, but use the data in it as a variable. Let me explain.
I have 3 variables $user, $item, $price. I want to be able to put those variables into a log file and when I read them again, be able to seperate them out so that I can do a db query on $item.
When I do this:
$logfile="log.txt";
$writelog = fopen($logfile, "a");
fwrite($writelog, $content);
fclose($writelog);
It writes to log file ok, but I'm not sure how to manupilate $content in order to have it do waht I need to, I need the values seperated so in one instance I did: $content="$user || $item || $cost"; Also, how do I make it do a "carriage return" action so that if I have another set of the same 3 values they are on a seperate line?
Now if I read this file:
$readlog = fopen($logfile, "r");
$content = fread($readlog, filsize ($logfile));
fclose($readlog);
It reads fine, and if I do echo $content;
I get: user's name || item # || $3.50
How can I pull out them in parts because I need to do a db query on both the user and the item, to display more info on each. plus when this happens, there may be more than 1 line, so I would just put into a loop, but I need to keep the values in seperated on each "set" of variables on a different line(I guess?)
Oh...and one other thing, after I view the file, would be better to have it wipe the log clean (what's the command to do that?) or have it delete and the file and get recreated the next time it needs it when it does fopen with "a"?
Thanks for all the help everybody and have a nice day.