Page 1 of 1

Find and replacing a word in a textfile

Posted: Wed Mar 17, 2004 11:23 am
by moop
Hi everybody,

I don't have a clue where to start on this but all I want is a simple script that opens a textfile and searches the content for a word like bold and replaces it with <b> then it writes the new word to the textfile.

I'm very new to PHP and I sure could use some help.

Many thanks

Re: Find and replacing a word in a textfile

Posted: Wed Mar 17, 2004 11:32 am
by TheBentinel.com
moop wrote:Hi everybody,

I don't have a clue where to start on this but all I want is a simple script that opens a textfile and searches the content for a word like bold and replaces it with <b> then it writes the new word to the textfile.

I'm very new to PHP and I sure could use some help.

Many thanks
You'll want to look into fopen, fread, fwrite, and possibly file_get_contents.
http://www.php.net/fopen
http://www.php.net/fread
http://www.php.net/fwrite
http://www.php.net/file_get_contents

and for the replace
http://www.php.net/str_replace

Posted: Wed Mar 17, 2004 12:21 pm
by moop
Yes thanks!