note 50677 deleted from function.file-put-contents by didou
| From: | didou@php.net | Date: | Mon, 07 Mar 2005 07:37:29 +0000 |
| Subject: | note 50677 deleted from function.file-put-contents by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-86022@lists.php.net to get a copy of this message | ||
Note Submitter: alan-php AT pixelsandpages DOT com
Reason: bad code
----
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
}
}
?>