问题
Is it possible to use fgetcsv
in PHP to open a tab-delimited file?
回答1:
$csvData = fgetcsv($fileHandle, 0, "\t");
Where $fileHandle
is a valid file handle. The 0 is just to tell the function not to limit seeking through lines (however you can change this to suit, the docs do say not imposing a limit decreases performance).
回答2:
Make sure to use double quotes around the "\t", single quotes will not work.
$fh = fopen($file, 'r');
while (($line = fgetcsv($fh, 0, "\t")) !== false) {
// do stuff
}
回答3:
yes, you can specify tab "\t" in its parameters. see the doc.
while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE)
来源:https://stackoverflow.com/questions/2582021/use-fgetcsv-for-tab-delimited-file