...
Excerpt |
---|
PHP provides useful functions can read text file directly instead of open → read → close: readfile(), file_get_contents() - personally I prefer to use file_get_contents(), because it does not display anything after reading the content. |
Option 1)
...
file_get_contents( $filename)
file_get_contents() returns string read from the source file requested.
Code Block |
---|
$src = "src/new.json"; $tmp = readfilefile_get_contents( $fileOriginal$src); echo $tmp; |
...
If you modify something and want to save that file, you can also use file_put_contents($filename, $src)
Option 2) readfile( $filename)
Unlike readfile() , it does not display anything on the screenreturn the text stream and shows its content while reading.
Code Block |
---|
$src = "src/new.json"; $tmp = file_get_contentsreadfile( $fileOriginal$src); echo $tmp; |