Need help: change a string in a file

From: Date: Wed, 06 Apr 2005 17:07:31 +0000
Subject: Need help: change a string in a file
Groups: php.general 
Request: Send a blank email to php-general+get-212452@lists.php.net to get a copy of this message
Hi All, I need some help in searching string in a file. My requirement is to search the string,append something to the string . Write the string back to the file without changing other parts of the file. e.g Suppose I have the following string in a file Set-Cookie: T_COOKIE=127.0.0.1-saswat-9; path=/ The fixed string is "Set-Cookie: T_COOKIE="and rest of the string is variable. I would like to change the string "127.0.0.1-saswat-9" to say "127.0.0.1-saswat-9-1234" My constraint is : I don't want to read the whole file into a buffer and work on that buffer as the file can be very large , sometimes more than 10 mb. My advantage is : I know that I will get the search string in first 200 bytes of the file , so I just need to read 200 bytes,play with that and write it back (overwriting the first 200 bytes with new 200 some bytes) .. Would appreciate any help or pointers. Thanks, -Saswat

« previous php.general (#212452) next »