İşlev CSV dosyası döndürür: onu kontrol hakkında gitmek nasıl?

2 Cevap php

Ben gibi bir şey yapıyorum:

$outputFile = getCurrentDBSnapshot($data);

$ veriler dosyası geçirerek ve izinler '+ w' yazma Fopen kullanarak açıyorum temelde komut isteminden, geçen am kaynak akışı nerede, şimdi getCurrentDBSnapshot bir tablo mevcut durumunu alacağı ve $ verileri güncelleştirmek csv dosyası, böylece temelde $ ÇıktıDosyası şimdi ben içine veri mevcut görmek için $ Outputfile değerini var_dump veya yazdırmak istiyorsanız, veritabanı tablo mevcut durumu ile güncellendi.

Ama ne yaparım

$this->fout = fopen($outputFile,'r') or die('Cannot open file');
$test = fgetcsv($outputFile,5000,";");
var_dump($test);

Bu parametre 1 bir dize türü olmasını beklediğini söyleyerek ve kaynak geçirerek bana bir hata verir.

My goal to see the contains of $outputFile

ve bu yüzden benim soru olduğunu

How can I see the contains present in $outputFile or how can I see what getcurrentDBSnapshot function is returning me ?

2 Cevap

fegtcsv ilk olarak bir dosya tanıtıcı, bir dosya adı parametre alır. Sen gibi bir şey yapmak gerekir:

$this->fout = fopen($outputFile,'r') or die('Cannot open file');
while ($test = fgetcsv($this->fout,5000,";"))
{
    var_dump($test);
}

fgetcsv sadece benzer fgets için, dosyanın tek bir satır alır unutmayın.

Ayrıca ben neden fgetcsv için üçüncü bağımsız değişken olarak bir noktalı virgül geçirerek emin değilim. CSV virgülle ayrılmış değer anlamına gelir; size dosya noktalı virgülle sınırlandırılmış olduğundan emin misin?

fgetcsv page of the manual, the first parameter passed to fgetcsv olmalıdır alıntı:

A valid file pointer to a file successfully opened by fopen(), popen(), or fsockopen().


Here, you are passing as first parameter $outputFile, which contains the name of the file you are trying to read from -- i.e. a string, and not a handle to an opened file.

Eğer fopen çağıran ve $this->fout, bu muhtemelen bu gibi fgetcsv geçirmeden gereken değişkendir onun dönüş değerini depolamak göz önüne alındığında:

$this->fout = fopen($outputFile,'r') or die('Cannot open file');
$test = fgetcsv($this->fout,5000,";");
var_dump($test);


As a sidenote : fgetcsv will only return the data of one line each time you call it -- which means you might have to use a loop, if you want to see the content of the whole file.

Gerekirse, the manual page of fgetcsv , Example #1 bakabilirsiniz.