soxxx85 Posted May 9, 2014 Share Posted May 9, 2014 Hi, I have a problem deleting duplicate rows in a .csv file. I have posted on another forum, but with no useful help, the file is still saving the row of .csv even in I write in a duplicate mobile number. The record file is only 2000 lines long and performance is not an issue. Please help, as it is time-sensitive. Cheers <?php$filename = "input.csv";$csv_output .= "\n";$title=$_GET[title];$fname=$_GET[fname];$sname=$_GET[sname];$notes=$_GET[notes];$mobile=$_GET[mobile];$string="$title,$fname,$sname,$mobile,$notes,$csv_output";$file = fopen($filename, "c"); flock($file, LOCK_EX); $stat = fstat($file)if($stat['size'] == 0) {// file created for the first timefwrite($file, "Title,First Name,Last Name,MobileNumber,Notes\n$string");flock($file, LOCK_UN);fclose($file);return; }while (($buffer = fgets($file, 2188)) !== false) {if(!stripos($buffer, $mobile) {$somecontent .= $buffer;}else {flock($file, LOCK_UN);fclose($file);return; }}// Otherwise fwrite() the lineelse {fwrite($file, $string);}flock($file, LOCK_UN);fclose($file);?> Quote Link to comment https://forums.phpfreaks.com/topic/288368-help-removing-duplicate-mobile-number-in-php-via-csv-file/ Share on other sites More sharing options...
ginerjm Posted May 9, 2014 Share Posted May 9, 2014 Your code is confusing after reading what you intend for it to do. How about putting some detailed comments in there to help guide us? Quote Link to comment https://forums.phpfreaks.com/topic/288368-help-removing-duplicate-mobile-number-in-php-via-csv-file/#findComment-1478889 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.