Skip to content
Bekijk in de app

Een betere weg om onze GTA community te volgen. Leer meer.

GTAGames.nl - De Nederlandse Grand Theft Auto Community!

Een volledig scherm app op het beginscherm inclusief notificaties, badges en meer.

Om deze app op je iPhone en iPad te installeren
  1. Druk op het icoon in Safari
  2. Scroll in het menu en druk op Zet op beginscherm.
  3. Druk op Voeg toe rechts bovenaan.
Om deze app op je Android toe te voegen
  1. Druk op het 3-punten menu (⋮) rechts bovenaan in de browser.
  2. Druk op Toevoegen aan beginscherm of Installeer app.
  3. Druk op Toevoegen om te bevestigen.

[PHP] fread() | wat doe ik fout?

Geplaatst:

Halloo...

Ik heb 2scripts gemaakt

'write.php' en 'read.php' waarin ik tekst in een bestand zet en de tekst er weer uit lees.

alleen als ik tekst in de file schrijf, en daarna nog een keer komt er dit in de file te staan

Test tekst. Test tekst

en bij het uitlezen komt er helemaal niks te staan..

hoe fix je dit?

// write.php
<?php
echo "Start";

$bestand = 'test.txt';
$tekst = "Test tekst. /n";

if (is_writable($bestand)) 
{
	if (!$handle = fopen($bestand, 'a')) 
	{
		echo "kan het bestand $bestand niet openen";
		exit;
	}

	if (fwrite($handle, $tekst) === FALSE) 
	{
		echo "kan niet scrijfen naar het bestand $bestand)";
		exit;
	}

	echo "$tekst is opgeslagen in $bestand";

	fclose($handle);

}
else
{
	echo "kan niet schrijven in het bestand $bestand";
}

?>

// read.php
<?php
$bestand =  "test.txt";

if (file_exists($bestand)) 
{
	$txt = fopen($bestand, "r");

	echo "Het bestand $bestand bestaat en is geladen";
	echo "/n";
	echo "De tekst is:";
	echo "/n";
	echo "%txt";

	fclose($txt);
} 
else 
{
	echo "Het bestand $bestand bestaat niet";
}

?>

Bewerkt: door Crusher!!

Featured Replies

Geplaatst:

in fopen() gebruik je mode 'a', die zet de file pointer aan het eind van het bestand, de pointer 'w' zet hem aan het eind

// write.php
<?php
.....
if (!$handle = fopen($bestand, 'w'))
.....
?>

Dit is overigens een voorbeeld voor het lezen van een bestand:

<?php
// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

echo $contents;
?>

Voor meer info:

http://nl3.php.net/manual/en/function.fopen.php

http://nl3.php.net/manual/en/function.fread.php

Geplaatst:
  • Auteur

Thnx maat.

Een reactie plaatsen

Je kan nu een reactie plaatsen en pas achteraf registreren. Als je al lid bent, log eerst in om met je eigen account een reactie te plaatsen.

Gast
Op dit onderwerp reageren...

Recent actief 0

  • Er zijn hier geen geregistreerde gebruikers aanwezig.

Account

Navigatie

Zoeken

Zoeken

Configureer push berichten

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.