file_put_contents() for PHP4

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;
        }
    }
}
?>

This entry was posted on Monday, September 10th, 2007 and is filed under php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.


Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

8 Responses to “file_put_contents() for PHP4”

  1. Adam Dempsey Says:

    Shouldn’t the title be file_put_contents?

  2. Stoyan Says:

    oops, thanks Adam!

  3. Sam Says:

    Thanks very much – a useful function!

  4. olivetalks » Blog Archive » Register_Globals Off and PHP4 Says:

    [...] a bit more research and I found out that the function which appears in the script from B&T’s Tips & Scripts: file_put_contents() works with PHP5 but not with PHP4 which is what I have. Some googling for “file_put_contents() for PHP4″ brings up quite a few implementations of the PHP5 file_put_contents() function for PHP4. The one I settled for can be found in Stoyan Stefanov’s blog phppied.com (thanks Stoyan!) [...]

  5. Surjit Says:

    thanks very much, it was very usefull for me

  6. Derek Says:

    (“Beginner”) Can you explain this a bit?

    If I have file_put_contents(“$archiveDir/$archiveFilename”, $output); how do I make it work using this?

  7. Unreal][ Says:

    Very usefull, thank you very much!

  8. Dora Says:

    Здорова просто хотел дать вам быстрый поклон.
    Текст в содержании, кажется, работают с экрана в Хрома.
    Я не уверен, что это форматирования вопрос или что-то делать с интернет-браузера совместимостью,
    но я думаю , что я запостил, чтобы вы знали.
    дизайн и стиль выглядят грандиозными!
    Надеюсь, что вы разрешитепроблемы решите в ближайшее время.
    Dora Привет

Leave a Reply