Bir CSV dosyası içine bir dizinin içeriğini saklamak ve php bir konuma kaydetmek için nasıl

3 Cevap php

I have an array which has the contents as the result of an sql query. I have been able to convert them into a CSV as well in the below format

2; Testing; IPTV; 9886784; 50061; 28/2/10 09:30:01 AM; 
3; Testing; IPTV; 9886784; 50061; 1/3/10 09:30:01 AM;
4; Testing; IPTV; 9886784; 50061; 2/3/10 09:30:01 AM;
5; Testing; IPTV; 9886784; 50061; 2/3/10 09:30:01 AM;

Şimdi bir .csv file içine bu değeri koymak ve bunu belirli bir konuma kaydetmek istiyorum.

Ben php kullanarak yukarıdaki nasıl yapabilirim?

Ben php yeni olduğum gibi nazik yardım

Kartik

3 Cevap

$ veri bir dosyaya yazılacak veri içeriyorsa, o zaman aşağıdakileri yapın:

<?php
   $filename = "mydata.cvs";
   $handle = fopen($filename, "w");
   fwrite($handle, $data);
   fclose($handle);
?>

İkinci fopen parametre dosyayı açmak için nasıl tanımlar. values mevcuttur şunlardır:

'r' Open for reading only; place the file pointer at the beginning of the file. 'r+' Open for reading and writing; place the file pointer at the beginning of the file. 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. 'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call.

CSV nasıl inşa edilir? Eğer csv.eg oluşturmak gibi fputcsv() kullanabilirsiniz

$list = array ("2; Testing; IPTV; 9886784; 50061; 28/2/10 09:30:01 AM;");    
$fp = fopen('file.csv', 'w');    
foreach ($list as $line) {
    fputcsv($fp, $line."\n");
}    
fclose($fp);