Creating A .csv Document With PHP

by Ben Sinclair
Webmaster-Resources101.com
Friday, 29th July 2005

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
Content-Disposition: "inline; filename=dates_of_year.csv"");
echo "Day,Month,Year";
echo "1,6,2011";
echo "3,11,2011";
echo "19,2,2011";
?>

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 2011
3 11 2011
19 2 2011

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 forward 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!


Options:
Printer Friendly

About The Author:

Ben Sinclair is the webmaster of Webmaster-Resources101.com, Webmaster-Forums101.com and DevTutors.com

Developer Categories



Developer Tutorials
ASP
CGI & Perl
CSS
Flash
HTML
Java
JavaScript
MySQL
PHP
Python
XML

Developer Documentation

Developer Tools



Search our Developer Tutorials
  The DevSyndicate Network