Adding PHP to a file from a specific position

In php, I open a text file and add it. However, I need to add 3 characters to the end of the file. In other words, I need to add / write from a specific location in the file.

Can anyone help?

Best wishes Luben

+3
source share
2 answers

You need to open the file for editing, find the desired position and then write to the file, for example:

<?php
  $file = fopen($filename, "c");
  fseek($file, -3, SEEK_END);
  fwrite($file, "whatever you want to write");
  fclose($file);
?>

Further link to php.net - fseek doc

Hope this helps.

+10
source

, , ( fread()), 3 , , .

, , / , . .

,

+1

All Articles