- BASICS
- Quotes
- Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
- Comparison
- Logical
- FUNCTION
- Definition
- Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
- Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
-
Read Csv
- File Contents
- Context
- Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
- Cookies
- Sessions
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);
Last update: 531 days ago