2

A user selects a number "$Num = $_POST['Number']" from a drop down to delete a line from a text file. Ex.

Cat
Dog
Mouse

Lets say they chose line 3. How do I delete the line in the file so it just prints:

Cat
Dog

using only the number they chose and not the actual words in the line?

Cvm192
  • 23
  • 1
  • 4

1 Answers1

6

Use this:

$row_number = 0;    // Number of the line we are deleting
$file_out = file("file.txt"); // Read the whole file into an array

//Delete the recorded line
unset($file_out[$row_number]);

//Recorded in a file
file_put_contents("file.txt", implode("", $file_out));
Dmitry Maslennikov
  • 338
  • 2
  • 8
  • 22