Nals Posted March 15, 2011 Share Posted March 15, 2011 Hello everyone, This is my first post and I need a little help. My knowledge of php is limited, so this question may look simple. English isn't my mother tongue, which you have probably noticed already. So, my problem: I 've made a a phpscript that adds text to a txt-file, that works perfect, but I also need something to delete some parts of the file. part of my html-code: <form method="POST" action="verwijderscript.php"> <table class="noborder"> <tr><td class="noborder"> <input type="text" id="verwijdertitel" name="verwijdertitel" size="40"> <input type="submit" name="s1" value="Verwijder Bericht" /> </td></tr> </table> </form> part of my txt-file: <div id="Testtitel"> <span class="subtitel">Testtitel</span> <span class="rechts">Gepost op 15/03/2011</span> <br> <img class="nieuws" src="image.gif"><br> texttexttexttexttext<br> texttexttext<br> text <div class="streep"></div> </div id="Testtitel"> <div id="Testtitel2"> <span class="subtitel">Testtitel2</span> <span class="rechts">Gepost op 15/03/2011</span> <br> <img class="nieuws" src="image2.gif"><br> texttexttexttexttext<br> texttexttext<br> text <div class="streep"></div> </div id="Testtitel2"> part of my php-code: <?php $titel = $_POST['verwijdertitel']; $oud = file_get_contents("data.txt"); $data = fopen("data.txt", "w+"); $nieuw = str_replace("id=\""$titel, "id=\"hidden", $oud); fwrite($data, "$nieuw"); fclose($data); header("refresh:0;url=http://www.test.com"); ?> css: #hidden{display:none;} Problem: parse error line 6 of php-file And I don't think this works if the error is solved. I don't have a MySQL database, that's why I use a txt files. What I try to do is to hide the div, it would be better to delete it, but than I need to work with regex, I guess Link to comment https://forums.phpfreaks.com/topic/230717-delete-text-from-a-txt-file/ Share on other sites More sharing options...
AbraCadaver Posted March 15, 2011 Share Posted March 15, 2011 You have an extra quote and a missing quote in the search arg: $oud = file_get_contents("data.txt"); $nieuw = str_replace("id=\"$titel", "id=\"hidden", $oud); file_put_contents($nieuw, "data.txt"); header("refresh:0;url=http://www.test.com"); Link to comment https://forums.phpfreaks.com/topic/230717-delete-text-from-a-txt-file/#findComment-1187821 Share on other sites More sharing options...
Nals Posted March 15, 2011 Author Share Posted March 15, 2011 file_put_contents($nieuw, "data.txt"); must be: file_put_contents("data.txt", $nieuw); And it works! Thank you for your help, AbraCadaver! Link to comment https://forums.phpfreaks.com/topic/230717-delete-text-from-a-txt-file/#findComment-1187853 Share on other sites More sharing options...
AbraCadaver Posted March 15, 2011 Share Posted March 15, 2011 file_put_contents($nieuw, "data.txt"); must be: file_put_contents("data.txt", $nieuw); And it works! Thank you for your help, AbraCadaver! Sorry. Going off memory. Link to comment https://forums.phpfreaks.com/topic/230717-delete-text-from-a-txt-file/#findComment-1187858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.