<?php
require 'class.b3rtCSVWriter.php';
// Create object and set filename and delimiter
$csvWriter = new b3rtCSVWriter();
$csvWriter->setFilename('./example.csv');
$csvWriter->setDelimiter(';');
// Write example data
// Associative arrays are supported; values are written, keys are ignored
$csvWriter->putRecord(
array('col1'=>'column 1', 'col2'=>'column 2', 'col3'=>'column 3'));
// Data with ; and "
$csvWriter->putRecord(
array(';a;', 'aa', 'a;a;a'));
$csvWriter->putRecord(
array('"b"', 'bb', 'b"b"b'));
$csvWriter->putRecord(
array('";c;"', 'cc', 'c;"c";c'));
// Data on multiple lines
$csvWriter->putRecord(
array('d', 'd
d', 'd
"
d
""
d'));
// Unicode data
$csvWriter->putRecord(
array('α', 'α;β', 'α"β"γ'));
// Done writing example data
// Print any errors that occurred
if ($csvWriter->getErrors())
{
echo "Errors:\n";
print_r($csvWriter->getErrors());
}
// Destroy object
unset($csvWriter);
?>
|