note 40492 added to function.fwrite

From: Date: Fri, 05 Mar 2004 11:34:53 +0000
Subject: note 40492 added to function.fwrite
Groups: php.notes 
Request: Send a blank email to php-notes+get-66291@lists.php.net to get a copy of this message
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; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.fwrite.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+40492 Delete -- http://master.php.net/manage/user-notes.php?action=delete+40492&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+40492&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#66291) next »