Quantcast
Channel: How to remove a line from text file using php without leaving an empty line - Stack Overflow
Browsing index pages (4 articles)

How to remove a line from text file using php without leaving an empty line

currently I am able to remove a specific line from text file using php. However, after removing that line, there will be an empty line left behind.Is there anyway for me to remove that empty line so...

View Article


Answer by Melsi for How to remove a line from text file using php without...

You can improve this by setting conditions to predict errors.<?PHP$file = "a.txt";$line = 3-1;$array = file($file);unset($array[$line]);$fp = fopen($file, 'w+');foreach($array as $line)...

View Article


Answer by Thusitha Sumanadasa for How to remove a line from text file using...

$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+");...

View Article

Answer by user2039981 for How to remove a line from text file using php...

Really? I find this muuuuch easier, only one line of code:file_put_contents($filename, str_replace($line . "\r\n", "", file_get_contents($filename)));

View Article
Browsing index pages (4 articles)


Latest Images