iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 17, 2008
Learn HTML forms
About
 
May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /PHP

Creating A .csv Document With PHP 

  Views:    11316
  Votes:    12
by Ben Sinclair 11/29/03 Rating: 

Synopsis:

If you want to allow you or your users to download data in a .csv file, read this tutorial!
Pages: 
The Article

This is a very basic script for creating a .csv file in PHP and is easy to set up and display information.

The Script

OK, here's the whole script. I'll explain how it works after:

<?php
header ("Content-type: application/csv\nContent-Disposition: \"inline; filename=dates_of_year.csv\"");

echo "Day,Month,Year \n\n";
echo "1,6,2003\n";
echo "3,11,2003\n";
echo "19,2,2004\n";
?>

As you can see it is very basic. It will look something like this when you open the .csv file:

 Day  Month  Year
     
 1  6  2003
 3  11  2003
 19  2  2004

How It Works

Very simple. For every box(See above) you want to display information in, you need to add a comma(,):

Day,Month,Year

And for every "break", you need to add a back slash and the letter n:

\n

Hope that helps you out in displaying data! You can aslo set it up to display MySQL results too!

Enjoy!

Pages: 



 
  Sponsors