|
Creating A .csv Document With PHP
|
|
Home Page :: Authors Login :: Author Signup :: Search :: More Articles
Home :: PHP/MySQL
|
Creating A .csv Document With PHP
By Ben Sinclair
Contact Ben Sinclair
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,2003\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 | 2003 |
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!
Discuss this in our Webmaster Forums
About The Author:
Ben Sinclair
Ben Sinclair is the Webmaster of Webmaster Resources 101(/)
|
|
|
Advertising
|
|
Advertise your website here. View Advertising Information.
|