Use fgetcsv for tab delimited file

半世苍凉 提交于 2019-12-21 03:09:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!