diff options
Diffstat (limited to 'examples/xml.php')
-rwxr-xr-x | examples/xml.php | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/examples/xml.php b/examples/xml.php index 3104680..86b34c9 100755 --- a/examples/xml.php +++ b/examples/xml.php @@ -4,16 +4,17 @@ 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->setFlags(SplFileObject::READ_AHEAD|SplFileObject::SKIP_EMPTY); $csv->setDelimiter(';'); -//since version 7.0 only 10 rows will be converted using the query options $csv->setOffset(1); $csv->setLimit(10); -$csv->addSortBy(function ($row1, $row2) { - return strcmp($row2[1], $row1[1]); //we order the result according to the number of firstname given -}); +$csv->addSortBy($func); $doc = $csv->toXML('csv', 'ligne', 'cellule'); $xml = $doc->saveXML(); header('Content-Type: application/xml; charset="utf-8"'); |