public function loadCSV()
{
$file = fopen($this->path, 'r');
$dbcnt = $this->getdbrows();
while(!feof($file))
{
if(fgetcsv($file)[$this->group] == '610')
{
$date = fgetcsv($file)[$this->datePos];
$num = $this->formatNum(fgetcsv($file)[$this->numPos]);
$rec = fgetcsv($file)[$this->recPos];
if(!(in_array($num, $this->filter)))
{
array_push($this->csvitem, $date . ';' . $num . ';' . $rec);
}
}
}
$this->writeCSV();
}因此,我使用fopen加载一个csv文件,然后逐行遍历它,并将date、num和rec保存到它们的变量中。然而,由于我一遍又一遍地阅读相同的文件。我希望不要一遍又一遍地存储旧数据。因此,我用$dbcnt得到了db行的数量,然后我希望从该行开始。
你有什么想法吗?
发布于 2014-01-27 22:55:44
我会使用。它非常快,并且支持一个很好的基于线的搜索功能:
public function loadCSV() {
$file = new SplFileObject($this->path);
$dbcnt = $this->getdbrows();
$file->seek($dbcnt); // <---- here
while (!$file->eof()) {
$record = $file->fgetcsv();
if ($record[$this->group] == '610') {
.. and so on..发布于 2014-01-28 16:00:07
这个来自@ex3v的链接确实帮助了我How do I open a file from line X to line Y in PHP?
我需要从$dbcnt中得到的只是一条if语句
if($dbcnt >= $line)
{
}其中$line是fgetcsv的每次重复的计数器
https://stackoverflow.com/questions/21383641
复制相似问题