Re: searching and replacing in a file

From: Date: Mon, 15 Dec 2003 09:51:44 +0000
Subject: Re: searching and replacing in a file
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-172724@lists.php.net to get a copy of this message
$filename = '/path/to/file.txt'; $contents = file_get_contents($filename); $contents = str_replace($search,$replace,$contents); $handle = fopen($filename, "w"); if (fwrite($handle, $contents)) { echo 'file write successful'; } else { echo 'file write failed'; exit; } fclose($handle); also - there's no need to enclose the variable $file in quotes here: > $fp = fopen("$file", "w+"); olinux --- Richard Kurth <rdkurth@directphp.com> wrote: > How can I read through a file and find a string and > then replace it with a > new string and then save the whole file. > __________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/

« previous php.general (#172724) next »