Jump to content

string build ....


matleeds

Recommended Posts

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

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.