Generating comma-separated data : CSV File « File Directory « PHP






Generating comma-separated data

 
<?php

$sales = array( array('Northeast',12.54),
                array('All Regions',1597.34) );

$fh = fopen('sales.csv','w') or die("Can't open sales.csv");
foreach ($sales as $sales_line) {
    if (fputcsv($fh, $sales_line) === false) {
        die("Can't write CSV line");
    }
}
fclose($fh) or die("Can't close sales.csv");

?>
  
  








Related examples in the same category

1.Making a CSV-formatted string
2.Parsing CSV Strings
3.Read csv file
4.Reading CSV data from a file
5.Tell the web client to view the CSV file in a seprate program
6.fgetcsv.php
7.Printing comma-separated data
8.Putting comma-separated data into a string