Ok, I have a function that pulls info out of DB, I want this info to be written to a textfile. Code looks like this.. $myFile = "../sitemap.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = 'displayInfo()'; fwrite($fh, $stringData); fclose($fh); PHP: There is of course an error, $stringdata needs to contain the output from the function or a variable with the function info in... My eyes hurt..reps going for help !
thanks fot the help, this still does not print the data into the text file. Just a blank t.xt file ! $myFile = "../sitemap.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = displayInfo(); fwrite($fh, $stringData); fclose($fh);
Why do you have an echo here? Anyway, you need to get the contents (file_get_contents) and then append the new data to the contents then put the contents (file_put_contents). so somethining like: <?php $myFile = "../sitemap.txt"; //get contents $fh = file_get_contents($myFile); //append $stringData = displayInfo(); $fh .= $stringData; //put file_put_contents($myFile, $fh); ?> Code (markup): But the other method might be better i'm just trying to explain this method
thanks for your help, adopting wd_2k6 's method still prints nothing to the text file. Odd as it looks as it should..
Do a test to see if displayUsers() is actually returning a value. If it isn't then nothing will be added to the text file.
File might be readonly but ya it must produce error / warning. Following must put contents to sitemap.txt, am not sure if you php distribution has this function. file_put_contents( "../sitemap.txt", displayInfo() ); PHP: IMPORTANT Make sure displayInfo() returns something. If it just displays as its name is, then it means it is not returning anything and file contents will be empty. In such case use following: <? ob_start(); displayInfo(); //output to be grabbed $data = ob_get_contents(); //store output to a variable ob_end_clean(); file_put_contents( "../sitemap.txt", $data ); ?> PHP: regards