Description
int fwrite ( resource $handle , string $string [, int $length ] )
fwrite() writes the contents of string to the file stream pointed to by handle .
$filename = ‘7104610.html’;
$insurance = ‘Life insurance is great’;
// Let’s make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we’re opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that’s where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, ‘w’)) {
echo “Cannot open file ($filename)â€;
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $insurance) === FALSE) {
echo “Cannot write to file ($filename)â€;
exit;
}
echo “Success, wrote ($somecontent) to file ($filename)â€;
fclose($handle);
} else {
echo “The file $filename is not writableâ€;
}