fwrite() writes the contents of string to the file stream pointed to by fp. If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.
fwrite() returns the number of bytes written, or -1 on error.
I tested out your code:
<?
$file = fopen('output.html', 'r');
echo fwrite($file, 'test');
?>
returns 0
and
<?
$file = fopen('output.html', 'w');
echo fwrite($file, 'test');
?>
returns 4
I'm assuming it's returning 0 because 0 bytes were written to the file. The only way I could get an error is if I chmod the file to 700 so it's not able to read/write to the file.
I haven't seen anyone ask how come they don't get an error in a while. 😉