suresh64633 Posted August 25, 2009 Share Posted August 25, 2009 I want to generate Tab separated (tab delimited) txt file through PHP. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted August 25, 2009 Share Posted August 25, 2009 what does your code look like so far? you will want to do something like this: <?php $fh = fopen('file.txt','w+'); while(...code for loop here...){ $row = array(); //Build an array of data fwrite($fh,implode("\t",$row).PHP_EOL); } fclose($fh); ?> Quote Link to comment Share on other sites More sharing options...
kickstart Posted August 25, 2009 Share Posted August 25, 2009 Hi Also consider the fputcsv function with a parameter for the delimiter. http://uk.php.net/manual/en/function.fputcsv.php Basically you put your fields into an array and then output the array as one line using the function. All the best Keith Quote Link to comment Share on other sites More sharing options...
suresh64633 Posted August 26, 2009 Author Share Posted August 26, 2009 Thanks for valuable comments. Txt files is created now i want it to be download through header() function. I try below code but it does not work. header("Location:".$fileName); header("Cache-Control: cache, must-revalidate"); header("Pragma: public"); header("Content-Disposition: attachment; filename=".$fileName); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.