PHP

  minte9
REMEMBERS




Last update:   29-10-2021

CSV

Reads a row from a previously opened CSV file into an array.
 
$fd = fopen("example.csv", "r");
while($row = fgetcsv($fd)) {
    print_r($row);
        // [0] => aa [1] => bb [2] => cc
        // [0] => dd [1] => ee [2] => ff
}
Writes the elements of an array in CSV format to an open file handle
 
$fd = fopen("example.csv", "w");
$arr = array(1,2,3);
fputcsv($fd, $arr); // 1,2,3

$arr = array('a', 'b', 'c');
fputcsv($fd, $arr, ";"); // a;b;c

$arr = array('"a"', '"b"', '"c"');
fputcsv($fd, $arr, ";");
    // """a""";"""b""";"""c"""

$arr = array('"a"', '"b"', '"c"');
fputcsv($fd, $arr, ";", "'"); // default delimiter: "
    // Output: "a";"b";"c"
Reads all data from the current position in an open file, until EOF ... and writes the result to the output buffer.
 
/* -- example.txt
    aaa
    bbb
    ccc        
*/

$file = fopen("example.txt","r");

// Read first line
fgets($file);

// Send rest of the file to the output buffer
fpassthru($file); // aaa rn bbb
fclose($file);

Questions    
File contents
        A B C D E F
🔔
1/1