-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathch6Listing6.3.php
More file actions
29 lines (27 loc) · 817 Bytes
/
ch6Listing6.3.php
File metadata and controls
29 lines (27 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
include_once('generalIncludes.php');
echo '<input id="chapter" type="hidden" value="6">';
echo ('<h2>Chapter 6 Files, Streams, and Network Programming - Paragraph paragraph Reading files with file handles</h2>');
echo ('<h3>Listing 6.3: open for reading and writing</h3>');
showcode(<<<'CODE'
$f = fopen('file.csv', 'a+');
while ($row = fgetcsv($f)) {
// handle values,
// NB: Appearently getcsv starts reading from the start, regardless of the 'a+'
}
$values = array(
"Davey Shafik",
"http://zceguide.com",
"Win Prizes!"
);
// append line to csv file
fputcsv($f, $values);
fclose($f);
echo 'If all went well, a file has now been created named file.csv, containing the arrayvalues.
Look for the file and check the contents.
Try refreshing and see what happens';
CODE
);
showcode(<<<'CODE'
CODE
);