matleeds Posted November 17, 2011 Share Posted November 17, 2011 HI, coming from a .net background and picking up php as I go along, I was wondering what the best way of designing the following task is in php. It's part of an appointmnet reminder app and the admin can amend the message that is sent out. The default message is currently stored in a db table and displayed in a multi line box on the admin web page. for example, "This is a an appointment reminder for *patient name*. You have an appointment on *date* with *customer name*." There's two parts relating to the message process. 1. Allowing the admin to amend the message (but ensuring the *variable markers* are left in tact, so I know where to stick the variables for part 2) 2. When the messages are being sent out (for each loop), inserting the *variables* into the message. I have no problem getting hold of the *name*, *date*, *customer* for each iteration in the for each loop. I'm sure people have done stuff like this before and in .net I would use a stringbuilder object but like i say, I'm not all that groovy on php at the mo. I was thinking of maybe a function that accepts thats passed the message, name, date, customer or something.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/251302-string-build/ Share on other sites More sharing options...
trq Posted November 17, 2011 Share Posted November 17, 2011 Given the string: $s = "This is a an appointment reminder for {patient_name}. You have an appointment on {date} with {customer_name}."; You could use a simple str_replace. echo str_replace(array('{patient_name}','{date}','{customer_name}'), array($patient_name, $date, $customer_name), $s); Quote Link to comment https://forums.phpfreaks.com/topic/251302-string-build/#findComment-1288893 Share on other sites More sharing options...
matleeds Posted November 17, 2011 Author Share Posted November 17, 2011 thanks bud, that's done the job nicely! Quote Link to comment https://forums.phpfreaks.com/topic/251302-string-build/#findComment-1288895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.