You want to send output to more than one filehandle; … Writing to Many Filehandles Simultaneously in PHP
You want to change a file without using a temporary … Modifying a File in Place Without a Temporary File in PHP