Jason Carson wrote:
Yes, I am trying to write stuff to a file with PHP but in between the
<?php ?> tags and without deleting what is already in the file.
The only way is to read the file into memory, manipulate it there, and
then rewrite it.
Use a regex to get rid of the last closing tag, append your new lines to
it, and then write it.
You probably want to do it atomic or you can end up with occasional
issues (broken pages that requested the file you are writing before it
is finished being written) and I don't know if php can do that.
Again that's where using a non php config file that is parsed by php.
You can make your edits, save the file to cache (IE APC) and then write
it. Files that need its contents can get it out of cache and only need
to read it from file if it isn't cached. Since you cache it before
writing, it will be in cache while it is being written.
Another advantage to not using php for the file, you can validate the
values before setting/using them and handle problems appropriately in
your code rather than have a completely broken site because the script
that wrote the file had a bug causing a ; not to be written under
certain conditions.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php