Skip to Main Content
PHP 5 Kochbuch, Third Edition
book

PHP 5 Kochbuch, Third Edition

by David Sklar, Adam Trachtenberg, Carsten Lucke, Matthias Brusdeylins, Ulrich Speidel, Stephan Schmidt
September 2009
Intermediate to advanced content levelIntermediate to advanced
912 pages
48h 11m
German
O'Reilly Verlag
Content preview from PHP 5 Kochbuch, Third Edition

1.9 Kommaseparierte Daten zerlegen

Problem

Ihnen liegen Daten im CSV-Format (Comma Separated Values) vor, beispielsweise eine aus Excel oder aus einer Datenbank exportierte Datei, und nun möchten Sie die Datensätze und Felder extrahieren und in ein Format bringen, das Sie mit PHP bearbeiten können.

Lösung

Wenn sich die CSV-Daten in einer Datei befinden (oder mittels einer URL verfügbar sind), können Sie die Datei mit fopen() öffnen und die Daten mit fgetcsv() einlesen. Folgendermaßen geben Sie die Daten in einer HTML-Tabelle aus:

$fp = fopen('sample2.csv','r') or die("Kann die Datei nicht öffnen"); print "<table>\n"; while($csv_line = fgetcsv($fp,1024)) { print '<tr>'; for ($i = 0, $j = count($csv_line); $i < $j; $i++) { print '<td>'.$csv_line[$i].'</td>'; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP programmieren unter Windows

PHP programmieren unter Windows

Arno Hollosi
CSS Kochbuch, 3rd Edition

CSS Kochbuch, 3rd Edition

Joergen Lang, Christopher Schmitt

Publisher Resources

ISBN: 9783868993271Purchase book