Search posts, tags, users, and pages
Follow me!: Follow @EricTheCoder_ Here is my cheat sheet I created along my learning journey. If you have any recommendations (addition/subtraction) let me know. PHP local server php -S localhost:3000 Comments // one line comment /* This is a mult...
Eric The Coder
@EricTheCoder · Montreal, Canada
My passion is to learn and share
Businessman and blogger. My passion is to learn and share! I work with #React, #Next and #Laravel. I am also a fan of #TailwindCSS
Markdown supported · ⌘↵ to post
Damien Genthial
Hello, Very nice cheat sheet, all the must know is there. I picked a little mistake in you file example :
//File read $file = fopen("test.txt", "r"); //Output lines until EOF is reached while(! feof($file)) { $line = fgets($file); echo $line. "<br>"; } fclose($file);
In order to detect end of file (and have feof return true), you must read after the last char (or line) in file. So you must read before the test (to detect an empty file) and read at the end of the loop (to avoid echoing an empty line) :
//File read $file = fopen("test.txt", "r"); //Output lines until EOF is reached $line = fgets($file); while(! feof($file)) { echo $line. "<br>"; $line = fgets($file); } fclose($file);
Damien Genthial
Hello, Very nice cheat sheet, all the must know is there. I picked a little mistake in you file example :
//File read $file = fopen("test.txt", "r"); //Output lines until EOF is reached while(! feof($file)) { $line = fgets($file); echo $line. "<br>"; } fclose($file);In order to detect end of file (and have feof return true), you must read after the last char (or line) in file. So you must read before the test (to detect an empty file) and read at the end of the loop (to avoid echoing an empty line) :
//File read $file = fopen("test.txt", "r"); //Output lines until EOF is reached $line = fgets($file); while(! feof($file)) { echo $line. "<br>"; $line = fgets($file); } fclose($file);