Jump to content

Delete line in file


dreamwest

Recommended Posts

this is my first go at file open and write. I need to delete a file on a specific line:

 

This file contains lines like

 

something|something

something|

something|something

something|something

 

So a error will script will output "ERROR on line 2 - something|"

 

$handle = @fopen("1.txt", "r");
if ($handle) {

$count = 1;
    while (!feof($handle)) {
        $buffer = trim(fgets($handle, 4096));
        //echo $buffer."<br>";
        
       $check = explode('|', $buffer);
        
        if ($check[1] == "" || $check[1] == " " ){
        echo "ERROR on line {$count} - {$buffer}<br>";
        }
       $count = $count +1;  
    }
    fclose($handle);
}

 

Now all i need to do is delete that whole line from the file

 

Link to comment
https://forums.phpfreaks.com/topic/172434-delete-line-in-file/
Share on other sites

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.