We Recommend

Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
Wicked Cool PHP contains a wide variety of scripts to process credit cards, check the validity of email addresses, template HTML, and serve dynamic images and text.


Posted By

mafro on 05/02/07


Tagged

file php4


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vali29


file_put_contents


Published in: PHP 


fileputcontents implementation for PHP4

  1. define('FILE_APPEND', 1);
  2.  
  3. function file_put_contents($filename, $data, $flag = false) {
  4. $mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a+' : 'w+';
  5. $fp = fopen($filename, $mode);
  6. if ($fp === false) {
  7. return 0;
  8. } else {
  9. if (is_array($data)) $data = implode($data);
  10. $bytes_written = fwrite($fp, $data);
  11. fclose($fp);
  12. return $bytes_written;
  13. }
  14. }

Report this snippet 

You need to login to post a comment.