03-11-2011

PHP Quick PHP write to file example

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 :

http://php.net/manual/en/function.fopen.php

Comments:

Your comment:

»
Klaas 08/11/2011, 4:00 pm
excist (!) ?

 

[x]