MemoryRefresh!

Read csv



Questions 1 Answers 0%

Pages   0 from 51
Questions   0 from 84

Reset



fgetcsv() - Gets line from file pointer and parse for CSV fields
<?php // Reads a row from a previously opened CSV file // into an enumerative array $fd = fopen("example.csv", "r"); while($row = fgetcsv($fd)) { print_r($row); // Array ( [0] => aa [1] => bb [2] => cc ) // Array ( [0] => dd [1] => ee [2] => ff ) } fputcsv() - Writes the elements of an array in CSV format to an open file handle
<?php $fd = fopen("example.csv", "w"); $arr = array(1,2,3); fputcsv($fd, $arr); // Output: 1,2,3 $arr = array('a', 'b', 'c'); fputcsv($fd, $arr, ";"); // Output: a;b;c $arr = array('"a"', '"b"', '"c"'); fputcsv($fd, $arr, ";"); // Output: """a""";"""b""";"""c""" $arr = array('"a"', '"b"', '"c"'); fputcsv($fd, $arr, ";", "'"); // default delimiter: " // Output: "a";"b";"c" fpassthru Reads all data from the current position in an open file, until EOF, and writes the result to the output buffer.
<?php /* -- example.txt aaa bbb ccc */ $file = fopen("example.txt","r"); fgets($file); // Read first line fpassthru($file); // Send rest of the file to the output buffer // Outputs: aaa rn bbb fclose($file);
Questions

Related pages

File open !
Read file !
Read csv !
File contents !
File cache and stats !
File lock !
File parse !
Context !
Network !


0% 100%
 
 
0 pages 51 pages
1) Reads a row from a previously opened CSV file





Last Review: n/a   Passed: n/a   Reviews: n/a   Next Review: n/a  


fgetcsv() - Gets line from file pointer and parse for CSV fields
<?php // Reads a row from a previously opened CSV file // into an enumerative array $fd = fopen("example.csv", "r"); while($row = fgetcsv($fd)) { print_r($row); // Array ( [0] => aa [1] => bb [2] => cc ) // Array ( [0] => dd [1] => ee [2] => ff ) } fputcsv() - Writes the elements of an array in CSV format to an open file handle
<?php $fd = fopen("example.csv", "w"); $arr = array(1,2,3); fputcsv($fd, $arr); // Output: 1,2,3 $arr = array('a', 'b', 'c'); fputcsv($fd, $arr, ";"); // Output: a;b;c $arr = array('"a"', '"b"', '"c"'); fputcsv($fd, $arr, ";"); // Output: """a""";"""b""";"""c""" $arr = array('"a"', '"b"', '"c"'); fputcsv($fd, $arr, ";", "'"); // default delimiter: " // Output: "a";"b";"c" fpassthru Reads all data from the current position in an open file, until EOF, and writes the result to the output buffer.
<?php /* -- example.txt aaa bbb ccc */ $file = fopen("example.txt","r"); fgets($file); // Read first line fpassthru($file); // Send rest of the file to the output buffer // Outputs: aaa rn bbb fclose($file);



More from Php

Basics
Variables
Operators
Function
Array
String
Streams
Uncategorized


More from Programming

Php
jQuery




Powered by minte9.com