How to remove duplicate emails in csv file - php

How to remove duplicate email address in different csv file
example:
I have 10.000 emails address (all_members.csv) after sent out > Then I received 2550 invalid email (invalid.csv)
I want to remove that "invalid email"
My Code "
<?php
$all = file('all_email.csv'); // all_members.csv
$invalid = file('invalid.csv'); // invalid_email.csv
$correctEmails=array_diff($all, $invalid);
foreach ($correctEmails as $email) { echo $email."<br>"; }
$result = array_intersect($all,$invalid);
?>
for remove email only > this php code is work.
the problem is if I want to remove emails under "Multiple columns" is Not work
anyone can help
I would greatly appreciate if you able to help me, thanks

I'd recommend encapsulating this in a function that streams each line, builds an array of field -> values then checks to see if the value is in the data you want to remove, if it's not, write the line to an out file.
Something like...
<?php
/**
* Given a CSV file to read, the delimiter, and what to remove, return the filtered CSV data
* #param $filename string The /path/to/file.csv
* #param $outputFile string Where to write the output CSV data to
* #param $delimiter string How the fields are delimited in the CSV
* #param $removeHeader string The header to remove data from
* #param $removeData array The data to omit from the output
*
* #return boolean
**/
function remove_duplicates($filename, $outputFile, $delimiter=',', $removeHeader, $removeData)
{
// If the file doesn't exist or isn't readable - return false
if(!file_exists($filename) || !is_readable($filename)) {
return false;
}
$header = null;
$validData = [];
$writeHandle = fopen($outputFile, 'w');
if (false !== ($readHandle = fopen($filename, 'r'))) {
//While there are rows in the CSV, get this as an array of values
while (false !== ($row = fgetcsv($readHandle, 1000, $delimiter))) {
//On the first iteration, get the headers from the CSV
if (!$header) {
$header = $row;
fputcsv($writeHandle, $header);
} else {
// Combine the headers with the row to create an associative array representing a line
$line = array_combine($header, $row);
// Looking at the removeHeader field in this line, check to see if the value is in removeData
if (!in_array($line[$removeHeader], $removeData) {
// If it's not, then it's a valid line
fputcsv($writeHandle, $line);
}
}
}
fclose($readHandle);
fclose($writeHandle);
}
// Return
return true;
}

Related

Unable to insert data in CSV file PHP

I am in process of inserting data in the desired CSV file from another CSV file.
CSV file is creating fine with out any problem but its is not insert array data in file.
It only inserts header on the first row.
Below is code I am trying:
date_default_timezone_set('America/New_York');
set_time_limit(0);
ini_set("memory_limit", -1);
$realPath = realpath( dirname(__FILE__) );
$path = $realPath.'/3pltracking/';
$files = scandir($path);
$FilePath = $path.$files[2];
$result = array();
$date = date('m-d-Y_his');
if (file_exists($FilePath))
{
if (($handle = fopen($FilePath, "r")) !== FALSE)
{
$i=0;
while (($data = fgetcsv($handle, 10000, ",")) !== FALSE)
{
$i++;
if($i==1) continue;
//$list = array('$data[2],$data[25],$data[4],$data[30],$data[41],$data[27]');
echo $data[2].",".$data[25].",".$data[4].",".$data[30].",".$data[41].",".$data[27];
echo "<br>";
$list = array($data[2].",".$data[25].",".$data[4].",".$data[30].",".$data[41].",".$data[27]);
// the problem is here I believe as it is empty array if I check it outside while loop
}
fclose($handle);
$headers = array('ReferenceNumber', 'TotalCartons', 'ShipCarrier', 'TrackingNum', 'FreightPP', 'TotalWeight');
$fp = fopen($realPath.'\3pltracking\TrackingFiles\Tracking_File_'.$date.'.csv', 'w');
fputcsv($fp, $headers);
foreach ($list as $line) {
$val = explode(",", $line);
fputcsv($fp, $val);
}
fclose($fp);
} else {
$body = "File Not Found";
}
}
Here is my CSV file data:
TransactionNumber,CustomerName,ReferenceNumber,PurchaseOrderNumber,ShipCarrier,ShipService,ShipBilling,ShipAccount,EarliestShipDate,CancelDate,Notes,ShipToName,ShipToCompany,ShipToAddress1,ShipToAddress2,ShipToCity,ShipToState,ShipToZip,ShipToCountry,ShipToPhone,ShipToFax,ShipToEmail,ShipToCustomerName,ShipToDeptNumber,ShipToVendorID,TotalCartons,TotalPallets,TotalWeight,TotalVolume,BOLNum,TrackingNum,TrailerNum,SealNum,ShipDate,ItemNumber,ItemQuantityOrdered,ItemQuantityShipped,ItemLength,ItemWidth,ItemHeight,ItemWeight,FreightPP,WarehouseID,LotNumber,SerialNumber,ExpirationDate,Supplier,Cost,FulfillInvShippingAndHandling,FulfillInvTax,FulfillInvDiscountCode,FulfillInvDiscountAmount,FulfillInvGiftMessage,SoldToName,SoldToCompany,SoldToAddress1,SoldToAddress2,SoldToCity,SoldToState,SoldToZip,SoldToCountry,SoldToPhone,SoldToFax,SoldToEmail,SoldToCustomerID,SoldToDeptNumber,FulfillInvSalePrice,FulfillInvDiscountPct,FulfillInvDiscountAmt
242328,PARADIGM TRENDS,123810,40-402849,CUSTOMER PICK UP,LTL,FreightCollect,,,,,HG BUYING- JEFFERSON DC 884,HG BUYING- JEFFERSON DC 884,125 LOGISTICS CENTER PKWY,,JEFFERSON,AL,30549,US,,,,,,,30,0,30,0.0174,,,,,,DOV3S,64,64,4,1,1,4,0,1,,,,,,0,0,,0,,,,,,,,,,,,,,,0,0,0
33,d,123810,40-402849,CUSTOMER PICK UP,LTL,FreightCollect,,,,,HG BUYING- JEFFERSON DC 884,HG BUYING- JEFFERSON DC 884,125 LOGISTICS CENTER PKWY,,JEFFERSON,AL,30549,US,,,,,,,30,0,30,0.0174,,,,,,DOV3S,64,64,4,1,1,4,0,1,,,,,,0,0,,0,,,,,,,,,,,,,,,0,0,0
44,PARAdgdfDIGM TRENDS,123810,40-402849,CUSTOMER PICK UP,LTL,FreightCollect,,,,,HG BUYING- JEFFERSON DC 884,HG BUYING- JEFFERSON DC 884,125 LOGISTICS CENTER PKWY,,JEFFERSON,AL,30549,US,,,,,,,30,0,30,0.0174,,,,,,DOV3S,64,64,4,1,1,4,0,1,,,,,,0,0,,0,,,,,,,,,,,,,,,0,0,0
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,BY3M,176,176,11,1,1,11,,,,,,,,,,,,,,,,,,,,,,,,,,0,0,0
There are so many ways of going about this... including str_getcsv($csvData). However here we'd go for something old-school & a bit twisted;-). We would create a Function that uses Regex and a Looping Construct to build-up the relevant CSV Data Structure. The Function below illustrates how. Also note that although we mentioned that this is a somewhat twisted, old-school approach: don't be fooled... because it does its thing still ;-).
<?php
$csvSourceFile = __DIR__ . "/1.csv";
$csvPreferredColumns = array('ReferenceNumber', 'TotalCartons', 'ShipCarrier', 'TrackingNum', 'FreightPP', 'TotalWeight');
$newCsvStrut = processCSVData($csvSourceFile, $csvPreferredColumns, __DIR__ . "/test.csv");
/**
* #param $csvSource // PATH TO THE MAIN CSV FILE
* #param array $csvPreferredColumns // ARRAY OF HEADER COLUMN-NAMES TO BE EXTRACTED FROM MAIN CSV
* #param null $newCSVFileName // NAME OF THE NEW CSV FILE TO BE CREATED.
* #return string
*/
function processCSVData($csvSource, array $csvPreferredColumns, $newCSVFileName=null){
// GET THE CONTENTS OF THE CSV FILE & STORE IT IN A VARIABLE
$csvData = file_get_contents($csvSource);
// SPLIT THE CONTENTS OF THE CSV FILE LINE BY LINE: THAT IS; AT THE END OF EACH LINE
// THUS CONVERTING THE DATA TO AN ARRAY...
$arrCsvLines = preg_split("#\n#", $csvData);
//FILTER OUT UNWANTED EMPTY VALUES FROM THE ARRAY
$arrCsvLines = array_filter($arrCsvLines);
// CREATE SOME VARIABLES TO BE USED WITHIN THE LOOP...
$strDataFinal = "";
$arrDataMain = $arrDataFinal = array();
// IF THERE IS MORE THAN ONE LINE IN THE ARRAY WE CREATED ABOVE,
// THEN CONTINUE PROCESSING THE DATA...
if($arrCsvLines && count($arrCsvLines)>0){
// SINCE THE HEADER IS ALWAYS THE FIRST LINE IN THE CHAIN,
// WE EXPLICITLY EXTRACT IT AND STORE IT IN A VARIABLE FOR LATER USE
$arrCsvHeaders = preg_split("#\,([\s\t]+)?#", $arrCsvLines[0]);
// NOW WE LOOP THROUGH ALL THE LINES WE CREATED BY SPLITTING THE CONTENTS
// OF THE CSV FILE AT THE END-OF-LINE BOUNDARY
foreach($arrCsvLines as $key=>$arrCsvLine){
// WE DON'T WANT ANYTHING AT INDEX "0" SINCE IT IS THE HEADER
// AND WE ALREADY DEALT WITH IT ABOVE....
// SO IF THE INDEX $key IS NOT 0, WE CAN CONTINUE PROCESSING
if($key != 0){
$arrDataTemp = array();
$arrTempCsvData = preg_split("#\,([\s\t]+)?#", $arrCsvLine);
foreach($arrTempCsvData as $iKey=>$sData){
$arrDataTemp[$arrCsvHeaders[$iKey]] = $sData;
}
$arrDataMain[] = $arrDataTemp;
}
}
foreach($arrDataMain as $iKey=>$subData){
$arrTempFinal = array();
foreach($subData as $key=>$data){
if(in_array($key, $csvPreferredColumns)){
$arrTempFinal[$key] = $data;
}
}
$arrDataFinal[] = implode(",\t", $arrTempFinal);
}
$arrDataFinal = array_merge( array(implode(",\t", $csvPreferredColumns)), $arrDataFinal);
$strDataFinal = implode("\n", $arrDataFinal);
if($newCSVFileName){
file_put_contents($newCSVFileName, $strDataFinal);
}
}
return $strDataFinal;
}
var_dump($newCsvStrut);
// PRODUCES SOMETHING SIMILAR TO THE LINES BELOW:
string 'ReferenceNumber, TotalCartons, ShipCarrier, TrackingNum, FreightPP, TotalWeight
123810, CUSTOMER PICK UP, 30, 30, , 0
123810, CUSTOMER PICK UP, 30, 30, , 0
123810, CUSTOMER PICK UP, 30, 30, , 0
, , , , , ' (length=204)

Turning indexed array to associative array that still works with a CSV file. -PHP

I can't seem to find an answer. Is there an easy way to change my array in the code, to an associative array?
NOTE:
-All the variables being assigned are declared already
-It basically creates an array from a csv file called staff data and loops through to find the next empty line then adds that row with data, then re-saves back into the csv file.
My problem is that I cannot figure out in the slightest how to change this array to an associative array that will still work with my code.. Any direction would be greatly appreciated. I hope my problem is clear.
// Grabs the csv file (and its existing data) and makes it into an array so the new data can be added to it.
$StaffDetails = array();
$lines = file('data/StaffData.csv', FILE_IGNORE_NEW_LINES);
foreach ($lines as $key => $value)
{
$StaffDetails[$key] = str_getcsv($value);
}
//This is a for loop that checks when there is an avaliable line to put the data into. It loops over the lines, until there is an empty spot for the new data //to go into.
//It will not run it if the full name is empty.
for ($i=0; $i<200; $i++) {
if(empty($StaffDetails[$i][0]) == false){ //If its full
}else if (empty($StaffDetails[$i][0]) == true){ //If it is empty
//This prints the details of this staff to that line in the data file. $i is the avaliable line found above.
$StaffDetails[$i][0] = $UserFullName;
$StaffDetails[$i][1] = $UserPhoneNumber;
$StaffDetails[$i][2] = $Gender;
$StaffDetails[$i][3] = $Birthday;
$StaffDetails[$i][4] = $TypeOfWork;
$StaffDetails[$i][5] = $StartingDate;
$StaffDetails[$i][6] = $AnnualLeaveLeft;
$StaffDetails[$i][7] = $SickLeaveLeft;
$StaffDetails[$i][8] = $ID;
$StaffDetails[$i][9] = $NumberOfWorkDaysAWeek;
$StaffDetails[$i][10] = $Monday;
$StaffDetails[$i][11] = $Tuesday;
$StaffDetails[$i][12] = $Wednesday;
$StaffDetails[$i][13] = $Thursday;
$StaffDetails[$i][14] = $Friday;
$StaffDetails[$i][15] = $Saturday;
$StaffDetails[$i][16] = $Sunday;
$StaffDetails[$i][17] = $UserUsername;
$StaffDetails[$i][18] = $UserPassword;
$StaffDetails[$i][19] = $Em1FullName;
$StaffDetails[$i][20] = $Em1PhoneNumber;
$StaffDetails[$i][21] = $Em2FullName;
$StaffDetails[$i][22] = $Em2PhoneNumber;
$i =201;
}
//Below saves the previous data and new changes to the csv file
//This opens the csv file as a write file
$MyCsvFile = fopen('data/StaffData.csv', 'w');
//This takes the array that has had data ddded to it and adds it to the file
foreach ($StaffDetails as $fields) {
fputcsv($MyCsvFile, $fields);
}
//This closes the file
fclose($MyCsvFile);
}

I want to fetch contents of a file.txt and print it only up to a certain keyword php

Let's consider that there is a text file called 1.txt which has the following content.
wow<br>wow<br>wow<!--Read More--><br>wow<br>wow<br>wow<br>wow<br>wow<br>wow<br>
I want to display its contents only upto the <!--Read More-->
Presently am using fopen command to read and display whole text file.
$file_handle = fopen("posts/1.txt", "r");
while (!feof($file_handle)) {
$line_of_text = fgets($file_handle);
print $line_of_text;
}
Kindly someone help me with this...
$file_handle = fopen("posts/1.txt", "r");
while ((!feof($file_handle) && (($line_of_text = fgets($file_handle)) != "<!--Read More-->"))
{
print $line_of_text;
}
Warning: This works only if your "stop text" is always on the same line
You can use strstr() function to check if the line you read contains the string on which to stop.
Calling it with your line as the first parameter, the string searched as the second and true as the third parameter will return false if the string searched is not in the line or it will return the part of the line before the string searched.
$file_handle = fopen("posts/1.txt", "r");
while (!feof($file_handle)) {
/* Retrieve a line */
$line_of_text = fgets($file_handle);
/* Check if the stop text is in the line. If no returns false
else return the part of the string before the stop text */
$ret = strstr($line_of_text, "<!--Read More-->", true);
/* If stop text not found, print the line else print only the beginning */
if (false === $ret) {
print $line_of_text;
} else {
print $ret;
break;
}
}

Is it possible to get a resource handle from file data?

I currently have a function that takes a csv file, and returns an array of the data from it. I want to minimally alter this function to take the file data instead of the file itself.
Using the following code, I would like to get a resource handle from the passed in data, instead of from a file so that I can keep the rest of the function the same. Is this possible?
public function returnRawCSVData($filepath, $separator = ',')
{
$file = fopen($filepath, 'r');
$csvrawdata = array();
//I WANT TO CHANGE $filepath to $file_data and get a resource from it to pass into fgetcsv below.
while( ($row = fgetcsv($file, $this->max_row_size, $separator, $this->enclosure)) != false ) {
if( $row[0] != null ) { // skip empty lines
}
}
fclose($file);
return $csvrawdata;
}
It seems you're looking for a way to create a new file resource from the source text?
If so, you can create a file resource in-memory like so:
/**
* Return an in-memory file resource handle from source text
* #param string $csvtxt CSV source text
* #return resource File resource handle
*/
public static function getFileResourceFromSrcTxt($csvtxt)
{
$tmp_handle = fopen('php://temp', 'r+');
fwrite($tmp_handle, $csvtxt);
return $tmp_handle;
}
/**
* Parse csv data from source text
* #param $file_data CSV source text
* #see self::getFileResourceFromSrcTxt
*/
public function returnRawCSVData($file_data, $separator = ',')
{
$file = self::getFileResourceFromSrcTxt($file_data);
$csvrawdata = array();
while( ($row = fgetcsv($file, $this->max_row_size, $separator, $this->enclosure)) != false ) {
if( $row[0] != null ) { // skip empty lines
// do stuff
}
}
fclose($file);
}
It's worth noting that you can also use "php://memory" in place of "php://temp" -- the difference being that 'memory' ONLY stores things in memory while 'temp' will store something in memory until it reaches a given size (the default is 2 MB), then transparently switch to the filesystem.
Find out more about what the php docs say on this topic ...
If you're trying to pass around file handles, you can treat them as such:
$in_file = fopen('some_file.csv', 'r');
// Do stuff with input...
// Later, pass the file handle to a function and let it read from the file too.
$data = doStuffWithFile($in_file);
fclose($in_file);
function doStuffWithFile($file_handle)
{
$line = fgetcsv($file_handle);
return $line;
}

How to delete a line from the file with php?

I have a file named $dir and a string named $line, I know that this string is a complete line of that file but I don't know its line number and I want to remove it from file, what should I do?
Is it possible to use awk?
$contents = file_get_contents($dir);
$contents = str_replace($line, '', $contents);
file_put_contents($dir, $contents);
Read the lines one by one, and write all but the matching line to another file. Then replace the original file.
this will just look over every line and if it not what you want to delete, it gets pushed to an array that will get written back to the file. see this
$DELETE = "the_line_you_want_to_delete";
$data = file("./foo.txt");
$out = array();
foreach($data as $line) {
if(trim($line) != $DELETE) {
$out[] = $line;
}
}
$fp = fopen("./foo.txt", "w+");
flock($fp, LOCK_EX);
foreach($out as $line) {
fwrite($fp, $line);
}
flock($fp, LOCK_UN);
fclose($fp);
It can be solved without the use of awk:
function remove_line($file, $remove) {
$lines = file($file, FILE_IGNORE_NEW_LINES);
foreach($lines as $key => $line) {
if($line === $remove) unset($lines[$key]);
}
$data = implode(PHP_EOL, $lines);
file_put_contents($file, $data);
}
Another approach is to read the file line by line until you find a match, then truncate the file to that point, and then append the rest of the lines.
This is also good if you're looking for a substring (ID) in a line and want to replace the old line with the a new line.
Code:
$contents = file_get_contents($dir);
$new_contents = "";
if (strpos($contents, $id) !== false) { // if file contains ID
$contents_array = explode(PHP_EOL, $contents);
foreach ($contents_array as &$record) { // for each line
if (strpos($record, $id) !== false) { // if we have found the correct line
continue; // we've found the line to delete - so don't add it to the new contents.
} else {
$new_contents .= $record . "\r"; // not the correct line, so we keep it
}
}
file_put_contents($dir, $new_contents); // save the records to the file
echo json_encode("Successfully updated record!");
}
else {
echo json_encode("failed - user ID ". $id ." doesn't exist!");
}
Example:
input: "123,student"
Old file:
ID,occupation
123,student
124,brick layer
Running the code will change file to:
New file:
ID,occupation
124,brick layer
All answeres here have in common, that they load the complete file into the memory. Here is an implementation of removing one (or more) line(s) without coyping the files content into a variable.
The idea is to iterate over the files lines. If a line should be removed, the lines length is added to the $byte_offset. The next line is then moved $byte_offset bytes "upwards". This is done with all following lines. If all lines are processed, the files last $byte_offset bytes are removed.
I guess that this is faster for bigger files because nothing is copied. And I guess that at some file size the other answers do not work at all while this one should. But I didn't test it.
Usage:
$file = fopen("path/to/file", "a+");
// remove lines 1 and 2 and the line containing only "line"
fremove_line($file, 1, 2, "line");
fclose($file);
The code of the fremove_line() function:
/**
* Remove the `$lines` by either their line number (as an int) or their content
* (without trailing new-lines).
*
* Example:
* ```php
* $file = fopen("path/to/file", "a+"); // must be opened writable
* // remove lines 1 and 2 and the line containing only "line"
* fremove_line($file, 1, 2, "line");
* fclose($file);
* ```
*
* #param resource $file The file resource opened by `fopen()`
* #param int|string ...$lines The one-based line number(s) or the full line
* string(s) to remove, if the line does not exist, it is ignored
*
* #return boolean True on success, false on failure
*/
function fremove_line($file, ..$lines): bool{
// set the pointer to the start of the file
if(!rewind($file)){
return false;
}
// get the stat for the full size to truncate the file later on
$stat = fstat($file);
if(!$stat){
return false;
}
$current_line = 1; // change to 0 for zero-based $lines
$byte_offset = 0;
while(($line = fgets($file)) !== false){
// the bytes of the lines ("number of ASCII chars")
$line_bytes = strlen($line);
if($byte_offset > 0){
// move lines upwards
// go back the `$byte_offset`
fseek($file, -1 * ($byte_offset + $line_bytes), SEEK_CUR);
// move the line upwards, until the `$byte_offset` is reached
if(!fwrite($file, $line)){
return false;
}
// set the file pointer to the current line again, `fwrite()` added `$line_bytes`
// already
fseek($file, $byte_offset, SEEK_CUR);
}
// remove trailing line endings for comparing
$line_content = preg_replace("~[\n\r]+$~", "", $line);
if(in_array($current_line, $lines, true) || in_array($line_content, $lines, true)){
// the `$current_line` should be removed so save to skip the number of bytes
$byte_offset += $line_bytes;
}
// keep track of the current line
$current_line++;
}
// remove the end of the file
return ftruncate($file, $stat["size"] - $byte_offset);
}
Convert text to array, remove first line and reconvert to text
$line=explode("\r\n",$text);
unset($line[0]);
$text=implode("\r\n",$line);
I think the best way to work with files is to act them like strings:
/**
* Removes the first found line inside the given file.
*
* #param string $line The line content to be searched.
* #param string $filePath Path of the file to be edited.
* #param bool $removeOnlyFirstMatch Whether to remove only the first match or
* the whole matches.
* #return bool If any matches found (and removed) or not.
*
* #throw \RuntimeException If the file is empty.
* #throw \RuntimeException When the file cannot be updated.
*/
function removeLineFromFile(
string $line,
string $filePath,
bool $removeOnlyFirstMatch = true
): bool {
// You can wrap it inside a try-catch block
$file = new \SplFileObject($filePath, "r");
// Checks whether the file size is not zero
$fileSize = $file->getSize();
if ($fileSize !== 0) {
// Read the whole file
$fileContent = $file->fread($fileSize);
} else {
// File is empty
throw new \RuntimeException("File '$filePath' is empty");
}
// Free file resources
$file = null;
// Divide file content into its lines
$fileLineByLine = explode(PHP_EOL, $fileContent);
$found = false;
foreach ($fileLineByLine as $lineNumber => $thisLine) {
if ($thisLine === $line) {
$found = true;
unset($fileLineByLine[$lineNumber]);
if ($removeOnlyFirstMatch) {
break;
}
}
}
// We don't need to update file either if the line not found
if (!$found) {
return false;
}
// Join lines together
$newFileContent = implode(PHP_EOL, $fileLineByLine);
// Finally, update the file
$file = new \SplFileObject($filePath, "w");
if ($file->fwrite($newFileContent) !== strlen($newFileContent)) {
throw new \RuntimeException("Could not update the file '$filePath'");
}
return true;
}
Here is a brief description of what is being done: Get the whole file content, split the content into its lines (i.e. as an array), find the match(es) and remove them, join all lines together, and save the result back to the file (only if any changes happened).
Let's now use it:
// $dir is your filename, as you mentioned
removeLineFromFile($line, $dir);
Notes:
You can use fopen() family functions instead of SplFileObject, but I do recommend the object form, as it's exception-based, more robust and more efficient (in this case at least).
It's safe to unset() an element of an array being iterated using foreach (There's a comment here showing it can lead unexpected results, but it's totally wrong: As you can see in the example code, $value is copied (i.e. it's not a reference), and removing an array element does not affect it).
$line should not have new line characters like \n, otherwise, you may perform lots of redundant searches.
Don't use
$fileLineByLine[$lineNumber] = "";
// Or even
$fileLineByLine[$lineNumber] = null;
instead of
unset($fileLineByLine[$key]);
The reason is, the first case doesn't remove the line, it just clears the line (and an unwanted empty line will remain).
Hope it helps.
Like this:
file_put_contents($filename, str_replace($line . "\r\n", "", file_get_contents($filename)));

Categories