Jump to content

Help removing duplicate mobile number in PHP via .csv file


soxxx85

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.