-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documentation Update: adding toXML documentation and a merge example
- Loading branch information
Showing
3 changed files
with
110 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
use Bakame\Csv\Writer; | ||
use Bakame\Csv\Reader; | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
//we are creating a CSV from a raw string | ||
$rawCsv = <<<EOF | ||
Melodie;6;F;2011 | ||
Melody;7;F;2011 | ||
Melvil;13;M;2011 | ||
Melvin;9;M;2011 | ||
Menahem;6;M;2011 | ||
Mendel;7;M;2011 | ||
Meriem;8;F;2011 | ||
Merlin;8;M;2011 | ||
Meryam;7;F;2011 | ||
EOF; | ||
|
||
$writer = Writer::createFromString($rawCsv); | ||
//because we raw string delimiter is ";" | ||
//the string delimiter MUST also be ";" | ||
$writer->setDelimiter(';'); | ||
|
||
//we are creating a CSV from a raw string | ||
$rawCsv2Merge = <<<EOF | ||
Ben,7,M,2007 | ||
Benjamin,78,M,2007 | ||
Benoît,17,M,2007 | ||
Berenice,19,F,2007 | ||
Bertille,9,F,2007 | ||
Bianca,18,F,2007 | ||
Bilal,26,M,2007 | ||
Bilel,7,M,2007 | ||
EOF; | ||
|
||
$csv2merge = Reader::createFromString($rawCsv2Merge); | ||
//because we raw string delimiter is ";" | ||
//the string delimiter MUST also be "," | ||
$csv2merge->setDelimiter(','); | ||
|
||
/* | ||
When merging multiples CSV documents don't forget to set the main CSV object | ||
as a `Bakame\Csv\Writer` object with the $open_mode = 'a+' to preserve its content. | ||
This setting is of course not required when your main CSV object is created from String | ||
*/ | ||
|
||
?> | ||
<!doctype html> | ||
<html lang="fr"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Merging 2 CSV documents</title> | ||
<link rel="stylesheet" href="example.css"> | ||
</head> | ||
<body> | ||
<h1>Using the Bakame\Csv\Writer class to merge two CSV documents</h1> | ||
<h3>The main Raw CSV</h3> | ||
<p><em>The delimiter is a ";"</em></p> | ||
<pre> | ||
<?=$writer?> | ||
</pre> | ||
<h3>The Raw CSV to be merge</h3> | ||
<p><em>The delimiter is a ";"</em></p> | ||
<pre> | ||
<?=$csv2merge?> | ||
</pre> | ||
<?php $writer->insertAll($csv2merge); //we are merging both documents as simple as that!!?> | ||
<h3>The Raw CSV after merging</h3> | ||
<p><em>Notice that after merging the data is semi-colon ";" separated</em></p> | ||
<pre> | ||
<?=$writer?> | ||
</pre> | ||
<h3>Tips</h3> | ||
<p> When merging multiples CSV documents don't forget to set the main CSV object | ||
as a <code>Bakame\Csv\Writer</code> object with the <code>$open_mode = 'a+'</code> | ||
to preserve its content. This setting is of course not required when your main CSV object | ||
is created from String</p> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters