0

file read and compare with array values and remove the row values from file
fopen("sample.txt",'rb');
read the first column content from file and compare with array value,if it matches then remove the entire row from file.

2
Contributors
3
Replies
16
Views
1 Year
Discussion Span
Last Post by pritaeas
0

sample.txt file has emailaddress,name,...
i.e email1,name1,...
email23,name,...
and in the array have some emailadresses
$arr = array("email1","email2");
so it has to check if the emailaddress is found in the file i need to remove the entire row.

$file_handle = fopen($reportfile, "rb");
$emaillist = array("email1","email2");
while (!feof($file_handle) ) {
$line_of_text = fgets($file_handle);
$parts = explode('\n', $line_of_text);
echo $parts[0] ;
if($parts[0] == $emaillist[$i])
{
    //remove the entire row
}
}

how to remove the row from file. and the data is not comparing.

Edited by malatamil

0

how to remove the row from file

Create a new array containing only the values you want to keep. At the end, overwrite your existing file.

the data is not comparing

$i is not initialized.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.