Re: best way to read a file
| From: | Justin French | Date: | Fri, 29 Mar 2002 01:29:46 +0000 |
| Subject: | Re: best way to read a file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-90633@lists.php.net to get a copy of this message | ||
while we're on the topic, what's the best way to append an CSV line onto the
end of a text file?
---mail.csv---
Justin,French,justin@indent.com.au\n
Fred,Flintstone,fred@bedrock.com\n
Barny,Rubble,barny@bedrock.com\n
---
I'd like to append a new line::
$newline = "Hank,Foo,hank@foo.com\n";
...onto the end of file. I guess the process is, but I'm keen to hear
improvements :)
<?
$newline = "Hank,Foo,hank@foo.com\n";
$file = "data/mail.csv";
$fp = fopen($file,'a+');
flock ($fp,2);
fwrite($fp,$newline);
fclose($fp);
?>
I can't find fulock(), so I guess closing the $fp unlocks the lock.
Many thanks,
Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------