PHP cheat sheet (updated to PHP 8.1)
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.com9 min read
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);