If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Extracting Text within [] in TinyMCE Textarea

I really need help. I have been researching this, and all I've accomplished is confusing myself even more!

I have a page that allows the user to edit an email. The text within the TinyMCE textarea is saved to the database. I need it to be able to use shortcuts such as [ShipDate] and [TrackingNumber], and then when the user clicks "Send Email", I will extract every one of these and replace it with a value from the database.

I am trying to figure out how to integrate preg_replace to accomplish this, but I'm confused by all the symbols that follow it, so I have no clue as to how I would signify the different types ([ShipDate] vs [TrackingNumber], etc.) I'm also not sure how to make sure it gets ALL of the "variables" from the text.

I also tried to figure out if there was a way to add a shortcode button to TinyMCE that would allow the user to simply click a button to insert the ship date, then process it when the email was sent, but didn't have any luck there either.

Can anyone help me figure out the best way to do this? An email may look like this:

Your order has shipped on [ShipDate] by [ShippingMethod]. Your tracking number is [TrackingNumber]. To track your order, go to [TrackingURL].

I don't know why I didn't think of this before...probably just overthinking it (I do that often)...

Anyway, I can do this using str_replace(). So I guess my only question now is if someone can help me with creating buttons on TinyMCE that when clicked, will add the appropriate "[string]" in the textarea. Everything I look up is for Wordpress! Thanks!

You could use str_replace() if you wanted to maintain a static map of characters / db values to replace...but the way to make it dynamic (so that you would never have to edit the code) and make it more plug and play, to work with multiple form / database combinations is like this: