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 Quote Link to comment 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"); Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.