Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of H. Poort  >  b3rtCSVWriter  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: b3rtCSVWriter
Generate CSV files in pure PHP
Author: By
Last change: Added comments
Date: 7 years ago
Size: 927 bytes
 

Contents

Class file image Download
<?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);
?>