Answer the question
In order to leave comments, you need to log in
What is wrong with the php code?
This crap first gives out 4, then 3 and that's it.
$f = fopen("db.txt", "r");
$c = $f + 1;
fclose($f);
$f = fopen("db.txt", "w");
fwrite($f, $c);
fclose($f);
echo $c;
Answer the question
In order to leave comments, you need to log in
If I understood correctly what you wanted to write, then:
<?php
$fd = fopen("db.txt", "r");
$data = fgets($fd);
fclose($fd);
$data = $data + 1;
$fd = fopen("db.txt", "w");
fwrite($fd, $data);
fclose($fd);
echo $data;
I hope not offtopic, but I'll leave it here:
Once
php.net/manual/ru/function.file-get-contents.php
and two
php.net/manual/ru/function.file-put-contents.php
fopen returns a resource type, why are you trying to do arithmetic with it?
You can also use fread to read the contents of a file. fopen - opens, and fread or fgets fetches the contents. With variable names +1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question