Posted By

spaceploitator on 11/26/10


Tagged

file String php5 to prepend


Versions (?)

PHP5 prepend string to file


 / Published in: PHP
 

URL: http://mgccl.com/2007/07/01/prepend-string-to-a-file-with-stream

A useful thingie posted by Mgccl at his site mgccl.com, just wanted to share with Snipplr.

  1. function prepend($string, $filename){
  2. $context = stream_context_create ();
  3. $fp = fopen($filename,'r',1,$context);
  4. $tmpname = md5($string);
  5. file_put_contents($tmpname,$string);
  6. file_put_contents($tmpname,$fp,FILE_APPEND);
  7. fclose($fp);
  8. unlink($filename);
  9. rename($tmpname,$filename);
  10. }

Report this snippet  

You need to login to post a comment.