i would like to store a string into a .php file,but as such , its a php script itself , in which i would like to add array(s),but so far i always append string like this
<?php
$.....
....
?>
but i would like to only add the content without opening and closing new block of code. so to have only one opening and closing of script , thus appending before the actual end of file. How can i efficiently move the pointer like this ?
my function so far looks like this
$fw = fopen('../Resource/articlelist.php',"a");
.....
fwrite ($fw,$diffWrite);
The PHP interpreter doesn't require a closing ?>
on the end of files, just omit that and you it will work the same.
(just to answer the title of the question)
For moving the internal pointer of the file resource, there's fseek().
$fd = fopen('file', 'a');
fseek($fd, -3, SEEK_END); // now the pointer is at the end -3 bytes
You can create a loop that reads in chunks from the end moving backwards and search for the first ?>
if you want to make this appending more robust.