bfrog
07-22-2004, 02:53 PM
I can use str_replace to replace all the occurrences of a string with a different value, but what's the most efficient way to do this for a file?
thanks
thanks
![]() | View Full Version : php - file search and replace? bfrog 07-22-2004, 02:53 PM I can use str_replace to replace all the occurrences of a string with a different value, but what's the most efficient way to do this for a file? thanks CrabbyX 07-22-2004, 03:24 PM <?php function str_replace_file( $search, $replace, $filename ) { $fp = fopen( $filename, "w+" ); fwrite( $fp, str_replace( $search, $replace, fread( $fp, filesize( $filename ) ) ) ); fclose( $fp ); } ?> |