Jump to content

Delete text from a txt-file


Nals

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.