note 40492 deleted from function.fwrite by aidan

From: Date: Thu, 26 Aug 2004 08:58:51 +0000
Subject: note 40492 deleted from function.fwrite by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75303@lists.php.net to get a copy of this message
Note Submitter: sybren at thirdtower dot com ---- An improvement of the code in the 1st comment. This function strictly (===) checks "false", so writing 0 bytes actually returns 0 instead of false. Also returns the number of bytes written instead of "true", to be more like the PHP5 function file_put_contents(). <?php if (!function_exists("file_put_contents")) { function file_put_contents($filename,$content) { $nr_of_bytes = 0; if(($file = fopen($filename, "w+")) === false) return false; if(($nr_of_bytes = fwrite($file,$content) === false) return false; fclose($file); return $nr_of_bytes; } } ?>

« previous php.notes (#75303) next »