Page is a not externally linkable
jatar_k - 8:04 pm on Dec 18, 2003 (gmt 0)
I am sure we can think of something ;) your order of events seems fairly straight forward 1. open the source file for read seems simple enough 1. open the source file for read 2. open destination file for write 3. get row from source - we'll put this into a while loop to continuously get rows until we have none left 4. reformat - since fgetcsv splits it up for us we are looking for the third element of the $row array $goodstuff = str_replace [ca.php.net]("¦",",",$row[2]); we may need to intialize $goodstuff inside the loop to be safe Note:Step 4 can be any type of reformatting that needs to be performed on the file contents. In this particular case we are removing fields but this would be the step where any reconstruction can be made. 5. write to destination 6. repeat- the while loop takes care of this step as well 7. close files so what does that leave us with? seems pretty straight forward, didn't test it obviously ;) WebmasterWorld breaks pipes so ¦ must be replaced with an unbroken pipe [edited by: jatar_k at 7:57 pm (utc) on Feb. 6, 2005]
Welcome to WebmasterWorld beatsie, Anyone have any ideas or suggestions for an approach to this problem?
2. open destination file for write
3. get row from source
4. reformat
5. write to destination
6. repeat
7. close files
$sfp = fopen [ca.php.net]('/path/to/source.csv','r');
$dfp = fopen('/path/to/destination.csv','w');
while ($row = fgetcsv [ca.php.net]($sfp,10000,",","")) {
}
$goodstuff .= "\n";
fwrite [ca.php.net]($dfp,$goodstuff);
fclose [ca.php.net]($sfp);
fclose($dfp); <?
$sfp = fopen('/path/to/source.csv','r');
$dfp = fopen('/path/to/destination.csv','w');
while ($row = fgetcsv($sfp,10000,",","")) {
$goodstuff = "";
$goodstuff = str_replace("¦",",",$row[2]);
$goodstuff .= "\n";
fwrite($dfp,$goodstuff);
}
fclose($sfp);
fclose($dfp);
?>