Jump to content

[SOLVED] append text in the beggining of a file


tivrfoa

Recommended Posts

unfortunately there is not a built in way to do that.  You have to basically grab the contents of the file and put it into a string or array and concat the new stuff to the string or array_unshift it to the array and rewrite the whole thing back to the file.

unfortunately there is not a built in way to do that.  You have to basically grab the contents of the file and put it into a string or array and concat the new stuff to the string or array_unshift it to the array and rewrite the whole thing back to the file.

thanks!

 

php core could create this =D

 

this is what I did and it's working:

 

$text = 'something';
$filename = 'your_file.txt';
$text .= file_get_contents($filename);
$f = fopen($filename, 'w') or die("can't open file");
fwrite($f, $text);
fclose($f);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.