Find and replacing a word in a textfile

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
moop
Forum Newbie
Posts: 2
Joined: Wed Mar 17, 2004 11:23 am

Find and replacing a word in a textfile

Post 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
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: Find and replacing a word in a textfile

Post 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
moop
Forum Newbie
Posts: 2
Joined: Wed Mar 17, 2004 11:23 am

Post by moop »

Yes thanks!
Post Reply