Skip to content
View in the app

A better way to browse. Learn more.

GTAGames.nl - De Nederlandse Grand Theft Auto Community!

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

fwriten

Welk van de onderstaande zou ik moeten gebruiken als ik via een input een .txt bestand zou willen wijzigen, maar als ik het wil wijzigen wil ik dat wat er al in het .txt bestand komt ook nog eens terug komt in het input.

r - lezen in een bestand, pointer aan het begin

r+ - lezen en schrijven in een bestand, pointer aan het begin

w - schrijven in een bestand, maakt het bestand eerst leeg

w+ - lezen en schrijven in een bestand, maakt eerst het bestand leeg

a - schrijven in een bestand, pointer aan het einde

a+ - lezen en scrhijven in een bestand, pointer aan het einde

x - schrijven in een bestand, werkt alleen als het bestand nog niet bestaat

x+ - lezen en schrijven in een bestand, werkt alleen als het bestand nog niet bestaat

Dit had ik dus al: (dankzij PatrickW)

<?php

$handle = fopen("tekst.txt","w");

fwrite($handle,$_POST["tekst"]);

fclose($handle);

?>

<form action="index.php" method="post">
<input type="text" name="tekst">
<input class="button" type="submit" value="save"/>

</form>

PS. Ik heb een nieuw topic gemaakt, want het begint slordig te worden in het PHP/HMTL hulptopic. Anders moet je het maar samenvoegen als het niet mag.

Edited by Woetsha

Featured Replies

Je hebt de 'a' optie nodig. Daarbij worden nieuwe dingen die je schrijft aan het eind geplakt van de bestaande inhoud van de file.

Dus de nieuwe data wordt "toegevoegd" aan de inhoud van het bestand.

  • Author

De eerste keer lukte het wel en daarna niet meer :{ . Zou het wel altijd moeten werken of soms wel en soms niet ? Hier een voorbeeldje en hier de tekst.

EDIT: Het werkt wel alleen wat trager ;) !

Trouwens ik wou eigenlijk wat je ziet in tekst.txt komt in het input, dus als value ofzo..

Ik had dit als idee...

<?php

$handle = fopen("tekst.txt","w");

fwrite($handle,$_POST["tekst"]);

fclose($handle);

?>

<form action="index.php" method="post">
<input type="text" name="tekst" value="<?php include ('tekst.txt') ?>">
<input class="button" type="submit" value="save"/>

</form>

Maar het werkt natuurlijk niet...

Edited by Woetsha

Makkie. :puh:

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
 #- Sla de tekst op.
 $data = $_POST['tekst'];

 #- Schrijf de tekst naar het bestand.
 if(file_put_contents('./tekst.txt', $data, FILE_APPEND) == false)
 {
die('Helaas, wegschrijven naar het doelbestand is niet gelukt.');
 }  

 echo 'Je tekst is toegevoegd!';
}

#- Haal de tekst op.
$inhoud = file_get_contents('./tekst.txt');

#- Sluit de php parser.
?>

<!-- Formulier: start. -->
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" action="POST">
 <textarea rows="30" height="30"><?php echo $inhoud; ?></textarea>
</form>
<!-- Formulier: einde. -->

  • Author

Bedankt, ziet er wel ingewikkelder uit :? .

Ik heb toch maar de manier van PatrickW gebruikt en daarin, inplaats van de input een tekstbox gebruikt en dan tussen de twee tags de 'include' geplaatst en zo lukt het wel.

Toch bedankt voor je reactie ;) !

Ingewikkeld? Sorry hoor, maar dit is toch wel php 101.

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...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.