File write; if file does not exist it will attempt to create it, also it will write to the end of the file
Code:
$data = 'Some text';
$filename = 'file.html';
$open = fopen($filename, "x+");
fwrite($open, $data);
fclose($open);
File write; if file does not exist it will attempt to create it, also it will write to the beginning of the file. Meaning that it will clear all the text within the document and replace it.
Code:
$data = 'Some text';
$filename = 'file.txt';
$open = fopen($filename, "w+");
fwrite($open, $data);
fclose($open);
File read; the contents of the file will be saved under the '$contents' variable.
Code:
$filename = 'file.txt';
$open = fopen($filename, "rb");
$contents = fread($open, filesize($filename));
fclose($open);