Click to See Complete Forum and Search --> : Writing to a text file in php?


xvszero
07-31-2007, 02:03 PM
Basically I have to write a program that takes in information from a MYSQL database, filters it, and then writes out the input to a text file.

I already have the taking in information and filtering through SQL, but I've never used SQL for anything other than writing out on the actual page.

How would I then get this selected information into a text file, delimited somehow?

hastx
07-31-2007, 04:42 PM
it's not much different than writing it to the display. you just have to direct it to the file, but you have to open the file in the appropriate mode, and close it when done.


$handler=fopen("file.txt","a+");//open the file
fwrite($handler,"your data");
fclose($handler);


you could also store the data to a variable and write it using file_put_contents()

xvszero
07-31-2007, 04:56 PM
Ah I see.

I was having problems with it for awhile then I realized I didn't have write to file priveleges, heh.