Csv File Generate

How to generate dynamically row wise print in Excel(CSV) file from PHP?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you're wanting to be able to offer a link to dynamically generate a CSV file for download, here's what I do:

  * if you're using sessions, you'll need this in order for it to work with Internet Explorer
  if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) {

    * grab your dynamic content here, be it from a file or from a database
   $content = /* whatever, but when querying from a database I always have it return as an array so I can loop it */;
   if (count($content) > 0) {
      * since we're sending header information, this needs to precede any output
     header('Content-type: text/comma-separated-values');
     header('Content-disposition: attachment; filename="YOUR_CSV_FILENAME.csv"');
     $csv = '"Header1", "Header2", "Header3"\015\012';
     foreach ($content as $row) {
       $csv .= '"' . $row['col1'] . '", '"' . $row['col2'] . '", "' . $row['col3'] . '"\015\012';
     echo $csv;

Open in new window

Hope that helps.
atulmodiAuthor Commented:
It is Not Fully Satisfactory Result but i got some Idea from this.
atulmodiAuthor Commented:
It's Partially Helpful to me i got some idea from the link you provide.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.