file_put_contents() for PHP4

September 10th, 2007. Tagged: php

Simplified, but still...

<?php
if (!function_exists('file_put_contents')) {
    function file_put_contents($filename, $data) {
        $f = @fopen($filename, 'w');
        if (!$f) {
            return false;
        } else {
            $bytes = fwrite($f, $data);
            fclose($f);
            return $bytes;
        }
    }
}
?>

Comments? Feedback? Find me on Twitter, Mastodon, Bluesky, LinkedIn, Threads