The following code tries to open a file , creates it if it doesn't exist, clears it if it does excist (!), then writes to it and closes it again.
$file = "test.txt"; $fh = fopen($file, 'w') or die("can't open file"); $stringData = "Bob"; fwrite($fh, $stringData); fclose($fh);
For more info see :