gri,
Does this operation need to occur on the remote server using only PHP?
My first thought is to use
diff to create list of changes and then
patch to apply them. This is easily done locally and you can upload the changes to the server. Otherwise, if you have the necessary rights on the server, you could do it all remotely via telnet or SSH. If not, you may be able to wrap it in PHP and execute it on the server that way?