Depending on the specifics, it might be easier to load the entire file into a string via file_get_contents(), or into an array via file(). Then you can change text as desired, then overwrite the file via file_put_contents() (implode()-ing the array first if you go that route).