Faced with such a problem: there is a file that contains a string list of information, that is:

1 2 3 

etc. I need to display checkboxes next to them in php so that I can mark and delete the line. How can this be done?

    3 answers 3

     <?php $file = 'ya.txt'; if(isset($_POST['nums'])) { $array = file('ya.txt'); if(is_array($_POST['nums'])) { foreach($_POST['nums'] as $ArrList) { unset($array[$ArrList]); } } file_put_contents($file, implode("", $array)); die("Файл сохранен!"); } $array = file($file); echo "<form method='post'>"; foreach($array as $ArrNum => $ArrList) { echo "<label><input type='checkbox' name='nums[]' value='$ArrNum'> $ArrList</label><br>"; } echo "<input type='submit' value='Обновить'></form>"; 
    • @ bazaev05 well, you’ll think it out yourself. I threw the method of implementation to you. - lampa
    • and what [in it] [1] difficult? Dear, get used to work with the documentation. And Google was created for a reason. [1]: php.net/manual/ru/control-structures.foreach.php - zenith

    This is elementary, Watson:

     <?php $f=file("file.txt"); foreach ($f as $key=> $value) { print "<input type='checkbox' name='del_$key' value='$value'>"; } ?> 

    Then implement file overwriting without unnecessary lines or search with deletion.

    • I feel you should learn php once again. f-tion file - puts everything into an array at once. If your line has any unique difference, then in order to find this difference, you still have to read all the lines in a row. If you know exactly where to start the output, then you need to use the file pointer. Ps I visited the idea that you probably want to display lines that make sense, bypassing the cap and / or komenty. - zenith

    And can each line be made an element of the array?

    • via serialize try - hetfield