johnwayne77 Posted April 29, 2009 Share Posted April 29, 2009 ok, i have : $fname = "data.csv"; $fhandle = fopen($fname,"r"); while (($data = fgetcsv($fhandle, 1000, ",")) !== FALSE) { $oldcat = array("\"40\"", "\"52\"", "\"54\""); $newcat = array("100x", "1000x", "10000x"); $data[2] = str_replace($oldcat, $newcat, $data[2]); } fclose($fhandle); so, i found column 3, searched and replaced the values i want but now... how do i apply the changes to the same csv file ? any ideas? would really be appreciated as i'm running my brains out thanks Quote Link to comment https://forums.phpfreaks.com/topic/156104-fgetcsv-fputcsv-help-cant-figure-out-how-to-do-both/ Share on other sites More sharing options...
ignace Posted April 29, 2009 Share Posted April 29, 2009 <?php $handle = fopen('data.csv'); $lines = array(); while ($data = fgetcsv($handle)) { $oldcat = array("\"40\"", "\"52\"", "\"54\""); $newcat = array("100x", "1000x", "10000x"); $data[2] = str_replace($oldcat, $newcat, $data[2]); $lines[] = $data; } while ($line = each($lines)) { fputcsv($handle, $line); } fclose($handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/156104-fgetcsv-fputcsv-help-cant-figure-out-how-to-do-both/#findComment-821786 Share on other sites More sharing options...
johnwayne77 Posted April 30, 2009 Author Share Posted April 30, 2009 it doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/156104-fgetcsv-fputcsv-help-cant-figure-out-how-to-do-both/#findComment-822472 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.