fwrite() example

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)”;

// Write $somecontent to our opened file.
if (fwrite($handle, $insurance) === FALSE) {
echo “Cannot write to file ($filename)”;

echo “Success, wrote ($somecontent) to file ($filename)”;


} else {
echo “The file $filename is not writable”;

King Php Science Welcome, you are from: