summaryrefslogtreecommitdiffstats
path: root/examples/xml.php
blob: 86b34c967b75b6c13a2fed968c4a027290405212 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

use League\Csv\Reader;

require '../vendor/autoload.php';

 //we order the result according to the number of firstname given
$func = function ($row1, $row2) {
    return strcmp($row2[1], $row1[1]);
};

$csv = Reader::createFromPath('data/prenoms.csv');
$csv->setEncodingFrom('ISO-8859-15');
$csv->setDelimiter(';');
$csv->setOffset(1);
$csv->setLimit(10);
$csv->addSortBy($func);
$doc = $csv->toXML('csv', 'ligne', 'cellule');
$xml = $doc->saveXML();
header('Content-Type: application/xml; charset="utf-8"');
header('Content-Length: '.strlen($xml));
die($xml);