Quantcast
Channel: Deleting Line from text file php - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Sebastian for Deleting Line from text file php

$
0
0

One approach could be to query the server with the string to be removed if no line can be equal to another one, e.g., delete.php?str=<your string> and do the deletion of that string (note that I said 'string' not line).

If it's possible for lines to be equal, you should identify the lines and follow a similar approach: delete.php?line=<number>.

This should be easy and you could write a flexible code that deletes lines from a giving file by also passing the filename.

Edit: Example provided following the advise of using a hidden field.

<?php$html = "<form id='form' method='post' action='delete.php'>";foreach(array("line 1", "line 2", "line 3") as $key => $value ) {    $html .= "<span>${value}</span>";    $html .= "<input type='hidden' name='lineNumber' value='${key}'>";    $html .= "<input type='submit' value='Delete' name='line'><br>";}$html .= "</form>";echo $html;?>

In your delete.php get the content of $_POST['lineNumber'] to retrieve the line number.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>