Jump to content

Recommended Posts

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 time
fwrite($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 line
else {
fwrite($file, $string);
}
flock($file, LOCK_UN);fclose($file);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.