note 50677 added to function.file-put-contents

From: Date: Mon, 07 Mar 2005 01:52:41 +0000
Subject: note 50677 added to function.file-put-contents
Groups: php.notes 
Request: Send a blank email to php-notes+get-86020@lists.php.net to get a copy of this message
For those of you like myself who don't have PHP 5 but want the simplicity of this function... Try this hack I wrote, which should do the same thing. I added it to the file I always INCLUDE which contains all my useful functions. As a bonus, this function will not be defined if you are using PHP 5 already. (That feature not tested because I don't have PHP 5) <?php if (!(function_exists(file_put_contents))){ function file_put_contents($fileName,$data){ if (!file_exists($fileName)){ touch($fileName); //create file if it does not exist } $fp = fopen($fileName,w); $success = fwrite($fp,$data); fclose($fp); return $success; //return bytes written or FALSE } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.file-put-contents.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50677 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50677&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50677&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50677&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50677&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50677&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50677&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86020) next »