I want to create an image Counter. Why does my code report an error and follow the video learning process?
The following describes the preparation of the image counter and the text counter.
If (! @ $ F = fopen ("num.txt", "r ")){
Echo "the file does not exist ";
$ Num = 0;
} Else {
Fgets ($ f, 10 );
Fclose ($ f );
}
$ Num ++;
$ Ff = fopen ("num.txt", "w ");
Fwrite ($ ff, $ num );
Fclose ($ ff );
Echo $ num;
?>
------------------------------------------------
The first normal operation, you can create a new num.txt file, and the counter jumps to 1
However, if you run it again, the number 2 should be displayed.
But it is shown as follows:
(! ) SCREAM: Error suppression ignored
(! ) Notice: Undefined variable: num in C: \ wamp \ www \ PHP100 \ PHP07-GraphicalCounter.php on line 42
Call Stack
# Time Memory Function Location
1 0.0006 253472 {main} () .. \ PHP07-GraphicalCounter.php: 0
1
Reply to discussion (solution)
Use the file_exists function to determine whether a file exists.
Does not exist: create a file and write 1
Yes: open the file, read the file content, add 1, and write
If (! @ $ F = fopen ("num.txt", "r ")){
Echo "the file does not exist ";
$ Num = 0;
} Else {
$ Num = fgets ($ f, 10 );
Fclose ($ f );
}
$ Num ++;
$ Ff = fopen ("num.txt", "w ");
Fwrite ($ ff, $ num );
Fclose ($ ff );
Echo $ num;
If (! @ $ F = fopen ("num.txt", "r ")){
Echo "the file does not exist ";
$ Num = 0;
} Else {
$ Num = fgets ($ f, 10 );
Fclose ($ f );
}
$ Num ++;
$ Ff = fopen ("num.txt", "w ");
Fwrite ($ ff, $ num );
Fclose ($ ff );
Echo $ num ......
Thank you! Problem changed
However, it is normal to be 1, 2, 3, 4, 5, 6
Mine is 1, 3, 5, 7, 9,
My test is normal and I don't know how you test it. Have you refreshed twice?
I am here to learn
My test is normal and I don't know how you test it. Have you refreshed twice?
No. I can't double-click it again if I click it once.
Is the increase of an even or odd number.
Another question is how to enable EclipsePHP Studio 3 to support Chinese naming.
I use a Chinese version, but an error is reported when the folder or file name contains Chinese characters. it is easy to use an English name.
Why should we name it in Chinese? Find yourself in trouble ..
Why should we name it in Chinese? Find yourself in trouble ..
Files are not needed, but folders generally prefer Chinese characters...
Please Jordan step: http://bbs.csdn.net/topics/390432008