Replace strings in text document?

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
Rob02
Forum Newbie
Posts: 1
Joined: Thu Jun 09, 2005 8:59 pm

Replace strings in text document?

Post by Rob02 »

Hey Guys,

For the life of me I can't figure out how to do this, and since I don't know the proper terms, I can't search the net for it.

Basically I have a mailing list program that has a regular text box titled "message". The message is then sent over to a php script that just takes the message and emails it to all the users in the MySQL database using arrays.

How would I go about having php analyze the message and change the strings to the data in the MySQL DB?

For example, if I typed %fname%, it would replace it with data in the fname column of MySQL?

Am I explaining myself right? Sorry for the confusion!

Thanks
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

str_replace, will do the trick for replacing in your strings.
then just do some magic MySQL-statement to get the "from" and "to"-values which you feed to str_replace.
Post Reply