php 对制表符分隔文件使用 fgetcsv
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2582021/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use fgetcsv for tab delimited file
提问by Brian
Is it possible to use fgetcsvin PHP to open a tab-delimited file?
是否可以fgetcsv在 PHP 中使用以打开制表符分隔的文件?
回答by alex
$csvData = fgetcsv($fileHandle, 0, "\t");
Where $fileHandleis 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 docsdo say not imposing a limit decreases performance).
$fileHandle有效的文件句柄在哪里。0 只是告诉函数不要限制通过行搜索(但是你可以改变它以适应,文档确实说不施加限制会降低性能)。
回答by Paul Richards
Make sure to use double quotes around the "\t", single quotes will not work.
确保在“\t”周围使用双引号,单引号不起作用。
$fh = fopen($file, 'r');
while (($line = fgetcsv($fh, 0, "\t")) !== false) {
// do stuff
}

